0

enter image description hereI am trying to move my selected Checkbox rows from one vf page to another, for that i am adding all selected item in a list and then moving to another vf page since i am using the same controller the value of that list should be available there but i am not getting anything please someone help me out.

My 1st vf page code--

<apex:page tabStyle="Opportunity" controller="GEN_ProductSelectionController" >
  <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
   </script> 

  <apex:form >
    <apex:pageBlock title="Find Product" >
     <apex:pageBlockButtons Location="Top" >
         <apex:commandButton value="Select" action="{!closeProduct}"/>
         <apex:commandButton value="Cancel" action="{!Reset}"/>
     </apex:pageBlockButtons>
     <h1>By Keyword</h1>
      <apex:pageBlockSection >
        <apex:inputText value="{!searchstring}"/> 
      </apex:pageBlockSection>
      <apex:commandButton value="Search records" action="{!search}" />
    </apex:pageBlock>

    <apex:pageBlock >


                <apex:pageBlockTable value="{!wrapProductList}" var="accWrap"   >
                    <apex:column >
                      <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                      <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column >  
                    <apex:outputlink value="https://ap1.salesforce.com/{!accWrap.pro.id}">{!accWrap.pro.Name}</apex:outputlink>  
                    </apex:column> 
                    <apex:column value="{!accWrap.pro.ProductCode}" />
                    <apex:column value="{!accWrap.pro.Description}" />
                    <apex:column value="{!accWrap.pro.Family}" />
                    <apex:column value="{!accWrap.pro.Type__c}" />

                    </apex:pageBlockTable>


        </apex:pageBlock>
  </apex:form>
</apex:page>

Controller--

public class GEN_ProductSelectionController {


     ID cid = ApexPages.currentPage().getParameters().get('id');

     public PageReference Reset() {
            return null;
     }


     public List<wrapProduct> wrapProductList {get; set;}
     public List<Product2> selectedProducts{get;set;}
     public List<OpportunityLineItem> closeProduct{get;set;}
     public List <Product2> pro {get;set;}  
     public String searchstring {get;set;}  

     public void search(){  
             wrapProductList = new List<wrapProduct>();
             string searchquery='select name,id,ProductCode,Description,Family,Type__c from Product2 where name like \'%'+searchstring+'%\' Limit 20';  

             for(Product2 a: Database.query(searchquery)) {
                  wrapProductList.add(new wrapProduct(a));
             }
     }  

    public GEN_ProductSelectionController(){
             wrapProductList = new List<wrapProduct>();

             for(Product2 a: [select Id, Name,ProductCode,Description,Family,Type__c from Product2]) {
             wrapProductList.add(new wrapProduct(a));
             }
    }

    public class wrapProduct {
            public Product2 pro {get; set;}
            public Boolean selected {get; set;}

            public wrapProduct(Product2 p) {
                pro = p;
                selected = false;
            }
    }

    public PageReference closeProduct() {
            selectedProducts = new List<Product2>();

            for(wrapProduct wrapProductObj : wrapProductList) {

                 if(wrapProductObj.selected == true) {
                  selectedProducts.add(wrapProductObj.pro);
                 }
            }
            PageReference pagePrice = new PageReference('/apex/GEN_MultiEdit?id='+cid);
            pageprice.setRedirect(true);
            return pageprice; 

    }

    public void closeAccou(){
            selectedProducts = new List<Product2>();

            for(wrapProduct wrapProductObj : wrapProductList) {

               if(wrapProductObj.selected == true) {
                   selectedProducts.add(wrapProductObj.pro);
               }
            }
              insert selectedProducts;


    }



}

Now my next vf page where i want to show that selected selected products GEN_MultiEdit

<apex:page tabStyle="Opportunity" controller="GEN_ProductSelectionController" >
 <apex:form >
 <apex:pageBlock >
<apex:pageBlockTable value="{!selectedProducts}" var="c" title="Selected Products">
<apex:column value="{!c.Name}" headerValue="Product Name"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Here i am trying to get those products name

enter image description here

6
  • Can you post error messages with line numbers?
    – powlo
    Commented Feb 12, 2016 at 13:40
  • @powlo there is no error, values are not visible,
    – Sharma_raj
    Commented Feb 12, 2016 at 14:24
  • 1
    @RAT__ Bit confusing. What do you mean move selected checkbox from one row to another VF page? Can just remove unnecessary code and explain what you are trying to do.
    – Ratan Paul
    Commented Feb 12, 2016 at 14:30
  • @Ratan i have added images, which tells that after selecting products i am trying to click select button which is redirecting to next page which should show these products those are selected
    – Sharma_raj
    Commented Feb 12, 2016 at 14:55
  • ignore that title Account Name, that should be Selected products
    – Sharma_raj
    Commented Feb 12, 2016 at 14:56

1 Answer 1

1

I believe that your issue is that you're setting pageprice.setRedirect(true); in your closeProduct() method.

Setting the redirect to true causes Salesforce to issue a completely new HTTP GET request. This redirect process also flushes the viewstate, which contains the information used to reconstruct the state of your controller.

This means that with setRedirect(true), all your information is lost unless you pass the information through a page parameter (or save it in an sObject and then query for the information in your controller's constructor).

remove pageprice.setRedirect(true);, and your second page should work as you expect.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .