You need to sign in to do that
Don't have an account?
Pass values on click of custom button to different pageblocksection on same page
Hi Everyone,
I have requirement to pass the selected values from one page block section to another page block section on the same VF page. currently I am passing the selected values to second VF page using PageReference. here is my code. please help me out. I 'm very new to VF and Salesforce.
/********************** Vfpage 1 ********************** /
<apex:page standardController="Product2" extensions="Product">
<apex:form >
Enter Search key: <apex:inputText value="{!searchkey}"/>
<apex:commandButton value="Search" action="{!search}"/>
<apex:commandButton value="Add To Cart" action="{!selectedValue}"/>
<br/>
<apex:pageBlock title="Product Details" tabStyle="Product__c">
<apex:pageBlockTable value="{!lsPwr}" var="tmpVar">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!tmpVar.isSelected}"/>
</apex:column>
<apex:column value="{!tmpVar.prodObj.name}" headerValue="Product Name"/>
<apex:column value="{!tmpVar.prodObj.Category__c}" headerValue="Product Category"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
/********************** Vfpage 2 ********************** /
<apex:page standardController="Product2" extensions="Product">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Selectedproducts}" var="c" id="table">
<apex:column value="{!c.prodObj.name}" headerValue="Product Name"/>
<apex:column value="{!c.prodObj.Category__c}" headerValue="Product Category"/>
<apex:column headerValue="Quantity">
<apex:inputText value="{!c.quantity }"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
/********************** Controller ********************** /
public class Product {
public Product() {
}
public Product(ApexPages.StandardController controller) {
}
public integer totalQuantity;
public list<ProductWarpper> getSelectedproducts() {
selectedProd = new list<ProductWarpper>();
for(ProductWarpper cCon:getProdName())
{
if(cCon.isSelected ==true)
{
selectedProd.add(cCon);
}
}
totalQuantity = selectedProd.size();
system.debug('Size of seletced Items' + totalQuantity);
return selectedProd;
}
public PageReference selectedValue() {
PageReference pageRef= new PageReference('/apex/AddSelectedProduct');
pageRef.setredirect(false);
return pageRef;
}
public String searchkey { get; set; }
public integer prc;
public class ProductWarpper{
public Product2 prodObj{get;set;}
public boolean isSelected {get;set;}
public integer quantity {get;set;}
}
public List<product2> lstProd{get;set;}
public list<product2> newLstProd{get;set;}
public list<ProductWarpper> lsPwr{get;set;} {lsPwr= new list<ProductWarpper>();}
public list<ProductWarpper> selectedProd{get;set;}
public PageReference search() {
lsPwr.clear();
lstProd= [select Name,Category__c from product2 where Name like :'%'+searchkey +'%' or Category__c like : '%'+searchkey +'%' ];
system.debug('Controller Class '+lstProd);
for(product2 prod : lstProd){
ProductWarpper prodwap = new ProductWarpper();
prodwap.prodObj= prod;
lsPwr.add(prodwap);
}
return null;
}
public list<ProductWarpper> getProdName(){
list<PricebookEntry> prclist = new list<PricebookEntry>();
newLstProd= [select Name,Category__c,id from product2 where Name like :'%'+searchkey +'%' or Category__c like : '%'+searchkey +'%' ];
set<id> ids = new set<id>();
system.debug('Controller Class '+lstProd);
for(product2 prod : newLstProd){
ProductWarpper prodwap = new ProductWarpper();
prodwap.prodObj= prod;
lsPwr.add(prodwap);
ids.add(prod.id);
}
prclist = [select UnitPrice from PricebookEntry where Product2Id in:ids ];
return lsPwr;
}
}
And I also need to display the product unit price to the 2 pageblocksection along with other deatils.
And Suggestion will be great help for me
Thanks & Reagrds,
Amit
this should help..
http://wiki.developerforce.com/page/Wrapper_Class
the way u've used the wrapper class is incorrect!!
Hi, following is the VF page and its asociated controller.
Here i am passing string input from one section of page to the other section of same page upon pressing the custom button. Hope this helps you in right direction.
-- Visual force Page --
<apex:page standardController="Account" extensions="PassBetweenSection">
<apex:form >
<apex:pageBlock >
<apex:pageblockSection title ="Input Section">
<apex:inputtext label="Input Here" value="{!YourinputText}"/>
<apex:commandbutton value="Input >> output" action="{!CallMethodetosetOutPutString}"/>
</apex:pageblockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageblockSection title ="Output Section">
<apex:outputtext label="Output Here" value="{!YourOutputText}"/>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
-- Controller --
public class PassBetweenSection {
Public string YourinputText{get;set;}
Public string YourOutputText{get;set;}
public PassBetweenSection(ApexPages.StandardController controller) {
}
public string CallMethodetosetOutPutString(){
YourOutputText = YourinputText ;
return null;
}
}
Hit kudos and mark this as answer if it helps you.
Thanks,
Yoganand.
Thanks Anup
Regards,
Amit
The Issue is, in the 2nd section I am passing the only selecetd value from the first section. now in the second section I have a command button {!removeItem} on click of this button the products thats has been selected using checkbox should be removed and it should display only the prodcuts which was not selected. I have used a wrapper class to display the selected prodcuts from 1st section to 2 section. but now I dnot know how to remove the items from the second section which all are selected.
Thanks in advance
Regards,
Amit
iterate over the wrapper put a if condition checking value to be false against the chkbox value
store it into a different list of type the wrapper and then show that list
Hi Anup,
i am using one more list of wrapper classs to add the Item which all are not selected and displaying that list to my VF page but I'm not getting the output. here is waht I'm trying to do ..
This is my method that will remove the selected Items and display only the items which are not selcted.
public PageReference removeItem(){
for(ProductWarpper cCon:getProdName()){
if(cCon.isSelected == false)
{
removedProd.add(cCon);
}
}
return null;
}
public list<ProductWarpper> getProdName(){
list<PricebookEntry> prclist = new list<PricebookEntry>();
newLstProd= [select Name,Category__c,id from product2 where Name like :'%'+searchkey +'%' or Category__c like : '%'+searchkey +'%' ];
set<id> ids = new set<id>();
system.debug('Controller Class '+lstProd);
for(product2 prod : newLstProd){
ProductWarpper prodwap = new ProductWarpper();
prodwap.prodObj= prod;
lsPwr.add(prodwap);
ids.add(prod.id);
}
and this is my VF page :
<apex:pageBlockTable value="{!removedProd}" var="r">
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!r.isSelected}"/>
</apex:column>
<apex:column value="{!r.prodObj.name}" headerValue="Product Name"/>
<apex:column value="{!r.prodObj.Category__c}" headerValue="Product Category"/>
</apex:pageBlockTable>
can you please give your valuble time to see my code and help me out where I'm doing mistake. I am new to Salesforce I'm finding it difficult to solve the issues.
you can take this as an example :
public class controller{
public list<ProductWrapper> listProductWrapper {get;set;}
public list<ProductWrapper> selectedProducts {get;set;}
public Controller(){
listProductWrapper = new list<ProductWrapper>();
selectedProducts = new List<ProductWrapper>();
}
public void submit(){
listProductWrapper.clear();
for(product__c prod: [Select name, name__c,MRP__c,Manufacturer_Name__c,Description__c,Bill_Price__c FROM product__c]){
listProductWrapper.add(new ProductWrapper(prod));
}
}
public void checkBill(){
for(ProductWrapper selectedProduct:listProductWrapper ){
if(selectedProduct.chkValue == true){
selectedProduct.total= (selectedProduct.qty)*(selectedProduct.productItem.BILL_Price__c);
selectedProducts.add(selectedProduct);
}
}
listProductWrapper.clear();
for(ProductWrapper pw:selectedProducts){
listProductWrapper.add(pw);
}
selectedproducts.clear();
}
}
Hi Anup,
Thanks for your solution, it has worked for me :). thanks a lot. I have modified a code bit. like this
public void remove(){
for(ProductWarpper cCon:selectedProd){
if(cCon.isSelected == false)
{
removedProd.add(cCon);
}
}
system.debug('RemoveItems :' + removedProd);
selectedProd.clear();
}
selectedProd : is a list of Wapper class which displays a selected value from pageblocksection_1 to pageblocksection_2. and I am using removedProd warpper list to display the items in pageblocksection_3 which was not selected in pageblocksection_2. and this is my VF page for section 2 :
<apex:outputpanel id="cartshow">
<apex:pageBlock title="Selected items" id="cartsho" mode="readonly" rendered="{!rendered}">
<apex:detail inlineEdit="true"/>
<apex:pageBlockButtons >
<apex:commandButton value="Place Order" action="{!OrderPlaced}"/>
<apex:commandButton value="Remove Items" action="{!removeItem}"/>
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Edit" action="{!Edit}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selectedProd}" var="c" >
<apex:column headerValue="Select" width="50px">
<apex:inputCheckbox value="{!c.isSelected}"/>
</apex:column>
<apex:column >
<apex:commandButton value="Edit" action="{!Edit}"/>
</apex:column>
<apex:column width="50px">
<apex:commandButton value="Remove" action="{!remove}"/>
</apex:column>
<apex:column value="{!c.prodObj.name}" headerValue="Product Name" width="390px"/>
<apex:column value="{!c.prodObj.Category__c}" headerValue="Product Category" width="390px"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
and For section 3 :
<apex:outputpanel id="afterremovedItems">
<apex:pageBlock title="Items" id="afterremoveditem" mode="readonly" rendered="{!removedProdRender}">
<apex:pageBlockTable value="{!removedProd}" var="r">
<apex:column value="{!r.prodObj.name}" headerValue="Name"/>
<apex:column value="{!r.prodObj.Category__c}" headerValue="Category"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
But I want insted of display the removedProd list view in different section or pageblocksection_3, I want it to display in pageblocksection_2 only. I mean In a form of reloading the second section. with new list value. can you suggest me whether I have to use actionfunction. or how I should approach.
Thanks in advance,
Regards
Amit
do not clear the list selectedProd.clear(); and then iterate over this list for the not selected products then display them in the 3rd section.. hope this helps....
Thanks & Reagrds,
Amit
Your suggestions has helped me to proceed with my work. thanks again.
Regards,
Amit