-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
3Questions
-
3Replies
on clicking on edit,field should be converted to edit
in this,i am referring two pages ,first one is to search for the products and add it to shopping cart in other page,now in other page i need some funtionality:
1.on delete , that item would be removed from cart and should display remaining items.
2.on edit, Quantity field should be converted to input field
3.on change of quantiy, amount should be updated.
i was able to implement delete,nut i m not able to implement 2 and 3,can anyone please resolve this issue.
it would be better if anyone could modify the code.
<apex:page controller="ProductSearchController" sidebar="false">
<apex:form >
<apex:pageBlock id="myBlock" >
<apex:variable value="{!0}" var="rowNumber" />
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!back}" value="Back"/>
<apex:commandButton value="Place Order"/>
</apex:pageBlockButtons>
<apex:pageMessages />
<apex:pageBlockSection Title="SHOPPING CART" id="Selected_PBS">
<!-- Here we will use an extra variable to define a row number -->
<apex:outputPanel id="panelWithVar">
<apex:variable value="{!0}" var="rowNumber" />
</apex:outputPanel>
<apex:pageBlockTable value="{!SelectedProducts}" var="p" id="newItems" >
<!-- A button to remove individual entry.
We must to pass the line number to define a list entry number to remove -->
<apex:column width="5%">
<apex:commandButton action="{!removeNewObject}" value=" delete " reRender="newItems,panelWithVar" > <!-- -->
<apex:param name="p1" value="{!rowNumber}" assignTo="{!numberOfRowToRemove}"/>
</apex:commandButton>
</apex:column> -->
<apex:column width="5%">
<apex:commandButton action="{!removeNewObject}" value=" edit " reRender="newItems,panelWithVar">
<apex:param name="p1" value="{!rowNumber}" assignTo="{!numberOfRowToRemove}"/>
</apex:commandButton>
</apex:column> -->
<apex:column headervalue="Name" value="{!p.pro.Name}" />
<apex:column headervalue="Code" value="{!p.pro.productcode}" />
<apex:column headervalue="Price" value="{!p.pro.price__c}" />
<apex:column headervalue="Quantity" value="{!p.quantity}"/>
<apex:column headervalue="Total Amount" value="{!p.amount}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public with sharing class ProductSearchController
{
public PageReference quicksave() {
return null;
}
/* public String getRowNumber() {
return null;
}*/
public class ProductWrapper {
public Boolean checked{ get; set; }
public Product2 pro { get; set;}
public double quantity{ get; set;}
public double amount{ get; set;}
public ProductWrapper(){
pro = new Product2();
checked = false;
quantity=1;
amount=quantity*pro.price__c;
}
public ProductWrapper(Product2 p){
quantity=1;
pro = p;
checked = false;
amount=quantity*pro.price__c;
}
}
// the results from the search. do not init the results or a blank rows show up initially on page load
public List<ProductWrapper> searchResults {get;set;}
// the categories that were checked/selected.
public List<ProductWrapper> selectedProducts {
get {
if (selectedProducts == null) selectedProducts = new List<productWrapper>();
return selectedProducts;
}
set;
}
// the soql without the order and limit
private String soql {get;set;}
// the collection of products to display
public List<Product2>Products {get;set;}
// the current sort direction. defaults to asc
public String sortDir
{
get
{
if (sortDir == null)
{
sortDir = 'asc';
}
return sortDir;
}
set;
}
// the current field to sort by. defaults to name
public String sortField
{
get
{
if (sortField == null)
{
sortField = 'Name';
}
return sortField;
}
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public ProductSearchController() {
soql = 'select name,productcode,price__c from Product2 where name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort()
{
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery()
{
try {
Products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
//change
if (searchResults == null) {
searchResults = new List<ProductWrapper>(); // init the list if it is null
} else {
searchResults.clear(); // clear out the current results if they exist
}
//change end
String name = Apexpages.currentPage().getParameters().get('name');
String productcode = Apexpages.currentPage().getParameters().get('productcode');
//String price=Apexpages.currentPage().getParameters().get('price');
soql = 'select name,productcode,price__c from product2 where name != null';
if (!name.equals(''))
soql += ' and name LIKE \''+String.escapeSingleQuotes(name)+'%\'';
if (!productcode.equals(''))
soql += ' and productcode LIKE \''+String.escapeSingleQuotes(productcode)+'%\'';
//if (!price.equals(''))
//soql += ' and price__c LIKE \''+String.escapeSingleQuotes(price)+'%\'';
for(Product2 p : Database.query(soql)) {
// create a new wrapper by passing it the category in the constructor
ProductWrapper pw = new ProductWrapper(p);
// add the wrapper to the results
searchResults.add(pw);
}
// run the query again
runQuery();
return null;
}
public PageReference next() {
// clear out the currently selected categories
selectedProducts.clear();
// add the selected categories to a new List
for (ProductWrapper pw : searchResults) {
if (pw.checked)
selectedProducts.add(new ProductWrapper(pw.pro));
}
// ensure they selected at least one category or show an error message.
if (selectedProducts.size() > 0) {
return Page.Category_Results;
} else {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Product.'));
return null;
}
}
public Integer numberOfRowToRemove { get; set; }
// The method to remove an item from the list
public PageReference removeNewObject(){
selectedproducts.remove(numberOfRowToRemove);
return null;
}
// fired when the back button is clicked
public PageReference back() {
return Page.assignment2;
}
}
- vin_89
- October 03, 2013
- Like
- 0
unable to search the by name or by product
public with sharing class ProductSearchController
{
// the soql without the order and limit
private String soql {get;set;}
// the collection of products to display
public List<Product2> Products {get;set;}
// the current sort direction. defaults to asc
public String sortDir
{
get
{
if (sortDir == null)
{
sortDir = 'asc';
}
return sortDir;
}
set;
}
// the current field to sort by. defaults to name
public String sortField
{
get
{
if (sortField == null)
{
sortField = 'Name';
}
return sortField;
}
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public ProductSearchController() {
soql = 'select name,productcode from Product2 where name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort()
{
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery()
{
try {
Products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String name = Apexpages.currentPage().getParameters().get('name');
String productcode = Apexpages.currentPage().getParameters().get('productcode');
soql = 'select name,productcode from product2 where name != null';
if (!name.equals(''))
soql += ' and name LIKE \''+String.escapeSingleQuotes(name)+'%\'';
if (!productcode.equals(''))
soql += ' and productcode LIKE \''+String.escapeSingleQuotes(productcode)+'%\'';
// run the query again
runQuery();
return null;
}
<apex:page controller="ProductSearchController" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Product" mode="edit">
<table width="100%" border="0">
<tr>
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria">
<script type="text/javascript">
function doSearch()
{
searchServer
(document.getElementById("name").value,
document.getElementById("productcode").value,);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="name" value="" />
<apex:param name="productcode" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">Name<br/>
<input type="text" id="name" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Product Code<br/>
<input type="text" id="productcode" onkeyup="doSearch();"/>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!Products}" var="Product">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Product.name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="productcode" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="productcode" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Product.productcode}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
<apex:pageBlock title="Debug - SOQL" id="debug">
<apex:outputText value="{!debugSoql}" />
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
i am unable to search product either by name or by product code,i tried a lot but i am unable to find tghe solution,can anyone please go through the code and say what i am doing wrong in the code.
- vin_89
- September 25, 2013
- Like
- 0
could any one please suggest some solution to this problem
Error:Could not resolve the entity from <apex:inputField> value binding '{!Product.Name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
could any one please suggest some solution to this problem
VF code:
<apex:page controller="ProductSearchController" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Product!" mode="edit">
<table width="100%" border="0">
<tr>
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria">
<script type="text/javascript">
function doSearch() {
searchServer(
document.getElementById("Name").value,
document.getElementById("Code").value,
);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="Name" value="" />
<apex:param name="Code" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">Name<br/>
<input type="text" id="Name" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Code<br/>
<input type="text" id="Code" onkeyup="doSearch();"/>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!Product2}" var="Product">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Product.Name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField/> value="{!Product.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Code" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Product.Productcode" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Product.ProductCode}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
<apex:pageBlock title="Debug - SOQL" id="debug">
<apex:outputText value="{!debugSoql}" />
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
ProductSearchController code:
public with sharing class ProductSearchController
{
public String getProduct() {
return null;
}
public String Product2 { get; set; }
// the soql without the order and limit
private String soql {get;set;}
// the collection of contacts to display
public List<Product2> Products {get;set;}
// the current sort direction. defaults to asc
public String sortDir
{
get
{
if (sortDir == null)
{
sortDir = 'asc';
}
return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField
{
get
{
if (sortField == null)
{
sortField = 'Name';
}
return sortField;
}
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public ProductSearchController() {
soql = 'select name,productcode from Product2 where name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort()
{
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery()
{
try {
Products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String Name = Apexpages.currentPage().getParameters().get('Name');
String Code = Apexpages.currentPage().getParameters().get('Code');
soql = 'select name,productcode from product2 where name != null';
if (!Name.equals(''))
soql += ' and product2.name LIKE \''+String.escapeSingleQuotes(Name)+'%\'';
if (!code.equals(''))
soql += ' and product2.productcode LIKE \''+String.escapeSingleQuotes(Code)+'%\'';
// run the query again
runQuery();
return null;
}
}
- vin_89
- September 18, 2013
- Like
- 0
unable to search the by name or by product
public with sharing class ProductSearchController
{
// the soql without the order and limit
private String soql {get;set;}
// the collection of products to display
public List<Product2> Products {get;set;}
// the current sort direction. defaults to asc
public String sortDir
{
get
{
if (sortDir == null)
{
sortDir = 'asc';
}
return sortDir;
}
set;
}
// the current field to sort by. defaults to name
public String sortField
{
get
{
if (sortField == null)
{
sortField = 'Name';
}
return sortField;
}
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public ProductSearchController() {
soql = 'select name,productcode from Product2 where name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort()
{
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery()
{
try {
Products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String name = Apexpages.currentPage().getParameters().get('name');
String productcode = Apexpages.currentPage().getParameters().get('productcode');
soql = 'select name,productcode from product2 where name != null';
if (!name.equals(''))
soql += ' and name LIKE \''+String.escapeSingleQuotes(name)+'%\'';
if (!productcode.equals(''))
soql += ' and productcode LIKE \''+String.escapeSingleQuotes(productcode)+'%\'';
// run the query again
runQuery();
return null;
}
<apex:page controller="ProductSearchController" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Product" mode="edit">
<table width="100%" border="0">
<tr>
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria">
<script type="text/javascript">
function doSearch()
{
searchServer
(document.getElementById("name").value,
document.getElementById("productcode").value,);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="name" value="" />
<apex:param name="productcode" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">Name<br/>
<input type="text" id="name" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Product Code<br/>
<input type="text" id="productcode" onkeyup="doSearch();"/>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!Products}" var="Product">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Product.name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="productcode" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="productcode" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Product.productcode}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
<apex:pageBlock title="Debug - SOQL" id="debug">
<apex:outputText value="{!debugSoql}" />
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
i am unable to search product either by name or by product code,i tried a lot but i am unable to find tghe solution,can anyone please go through the code and say what i am doing wrong in the code.
- vin_89
- September 25, 2013
- Like
- 0
could any one please suggest some solution to this problem
Error:Could not resolve the entity from <apex:inputField> value binding '{!Product.Name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
could any one please suggest some solution to this problem
VF code:
<apex:page controller="ProductSearchController" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Product!" mode="edit">
<table width="100%" border="0">
<tr>
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria">
<script type="text/javascript">
function doSearch() {
searchServer(
document.getElementById("Name").value,
document.getElementById("Code").value,
);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="Name" value="" />
<apex:param name="Code" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">Name<br/>
<input type="text" id="Name" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Code<br/>
<input type="text" id="Code" onkeyup="doSearch();"/>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!Product2}" var="Product">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Product.Name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField/> value="{!Product.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Code" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Product.Productcode" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Product.ProductCode}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
<apex:pageBlock title="Debug - SOQL" id="debug">
<apex:outputText value="{!debugSoql}" />
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
ProductSearchController code:
public with sharing class ProductSearchController
{
public String getProduct() {
return null;
}
public String Product2 { get; set; }
// the soql without the order and limit
private String soql {get;set;}
// the collection of contacts to display
public List<Product2> Products {get;set;}
// the current sort direction. defaults to asc
public String sortDir
{
get
{
if (sortDir == null)
{
sortDir = 'asc';
}
return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField
{
get
{
if (sortField == null)
{
sortField = 'Name';
}
return sortField;
}
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public ProductSearchController() {
soql = 'select name,productcode from Product2 where name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort()
{
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery()
{
try {
Products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String Name = Apexpages.currentPage().getParameters().get('Name');
String Code = Apexpages.currentPage().getParameters().get('Code');
soql = 'select name,productcode from product2 where name != null';
if (!Name.equals(''))
soql += ' and product2.name LIKE \''+String.escapeSingleQuotes(Name)+'%\'';
if (!code.equals(''))
soql += ' and product2.productcode LIKE \''+String.escapeSingleQuotes(Code)+'%\'';
// run the query again
runQuery();
return null;
}
}
- vin_89
- September 18, 2013
- Like
- 0