0

The idea:

  • Do a search, and shows a List with Select Option
  • Select some items and send it to a new Page (just those witch I selected)

The problem:

  • In the new page, is showing all the searched list with all item(selecteds and the others). I don't know what to do anymore.

Here is my code:

APEX CODE

public class wSearchP2 {

public wSearchP2() {

}


public Product2 p2 {get; set;} 
public boolean selected {get; set;}
public List<wSearchP2> searchs {get; set;} 
public List<Product2> selectedProducts {get; set;} 
public string keyword;


public wSearchP2(Product2 p2) {
    this.p2 = p2;
    selected = false;
    }
public void setKeyword(string keyword){
    this.keyword = keyword;
}
public string getKeyword(){
    return this.keyword;
}

public List<wSearchP2> getSearchs(){
    if(searchs == null){
        searchs = new List<wSearchP2>();
        for (Product2 p2 :Database.query('SELECT Id, Name,Codigo__c,Marca__c FROM Product2 WHERE Name Like :keyword OR Name Like \'%' + keyword + '%\'')){
            searchs.add(new wSearchP2(p2));
        }
    }
    return searchs;
}

public List<Product2> processSelectedProducts() {
  selectedProducts = new List<Product2>();
  for (wSearchP2 p2 :getSearchs()) {
      if (p2.selected == true) {
          selectedProducts.add(p2.p2);
      }
  }
    return selectedProducts;
}
 public PageReference getPage2() {
  processSelectedProducts();
  return Page.vAgoraVai;
}

public PageReference search_now() {
    getSearchs();
    return null;
}

}

VISUALFORCE CODE

<apex:page controller="wSearchP2">
<apex:form >
<apex:pageBlock >
        <apex:pageBlockTable value="{!selectedProducts}" var="produto">
            <apex:column >
             <apex:inputCheckbox value="{!produto.selected}" />
             <apex:outputLabel value="{!produto.p2.name}" /> 
             <apex:outputLabel value="{!produto.p2.Codigo__c}" /> 
             <apex:outputLabel value="{!produto.p2.Marca__c}" /> 
            </apex:column>
        </apex:pageBlockTable>
  </apex:pageBlock>
  </apex:form>
  </apex:page>

And the NEW PAGE

<apex:page controller="wSearchP2">
<apex:form >
<apex:pageBlock >
    <apex:inputText value="{!keyword}"/>
    <apex:commandButton value="Search" action="{!search_now}" />
        <apex:pageBlockTable value="{!searchs}" var="produto">
            <apex:column >
                <apex:outputLabel value="{!produto.p2.name}" /> 
       <apex:inputCheckbox value="{!produto.selected}" />
            </apex:column>
        </apex:pageBlockTable>
     <apex:commandButton action="{!getPage2}" value="go"/>
</apex:pageBlock>
</apex:form>
</apex:page>
  • 1
    selectedProducts is a Product sObject list then How are you using it as wrapper list? confirm you are going from New page to VISUALFORCE CODE page. – Tushar Sharma Nov 16 '16 at 17:16
  • FYI, using the same class for your controller and for the wrapper makes your code harder to follow. You can add a nested class to the controller class to use as the wrapper. – Keith C Nov 16 '16 at 18:00
  • you could use same controller for both the pages and use the data seamlessly.. – San Tosh Nov 16 '16 at 20:01
0

In your method. Use setRedirect(false) to get the same values in different page

public PageReference getPage2() {
  processSelectedProducts();
  PageReference pr =  Page.vAgoraVai;
   pr.setRedirect(false);
   return pr;
}
  • Didn't work too , it's showing all the items – Julio C. Boll Nov 16 '16 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.