function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Search and Configuration Page loading three times. How to reduce

My search and  configuration page is loading three times throughout the configuration process.

1. When the page loads.
2. When I search for results

3. When I select a result and the selection is displayed below the result list.

How can  I disply the selected result without rerendering the page?

VF page:

<apex:page standardcontroller="Customer_Product_Line_Item__c" extensions="AddCustomerProductStage1vfhide1" >

<!-- Javascript function to check all rows in the table -->
function checkAll(cb)
   var inputElem = document.getElementsByTagName("input");
   for(var i=0;i<inputElem.length;i++)
                   inputElem[i].checked = cb.checked;
<!-- End of Javascript function -->
<apex:form >
<apex:pageblock title="Choose Customer Product">
    <!-- Panel grid to display boxes o accept user input values -->
    <apex:panelGrid columns="2">
        <apex:outputLabel style="font-weight:bold;" value="Customer Product" ></apex:outputLabel>
        <apex:inputText value="{!userinput}" />

    <!-- End of panelgrid -->
    <!-- Div to position the commandbutton appropriately -->
        <div style="position:relative;left:75px;">
             <apex:commandButton value="Search" action="{!cpsearch}"  />

<!-- Display search results -->
<apex:pageblocksection columns="1" title="Customer Product Search Results" >
  <apex:outputpanel id="Contactlist">

        <apex:pageBlockTable value="{!results}" var="cp" >
             <apex:column width="25px" >
                <apex:outputPanel >
                    <apex:inputCheckbox value="{!cp.selected}" id="selectLine1">
            <apex:actionSupport event="onchange" rerender="thePageBlock"
              <apex:actionStatus startText="applying value..." id="status"/>
            </apex:outputPanel >
            <apex:column headervalue="Customer Product">
                <apex:outputtext value="{!cp.con.Name}"/>
        </apex:pageBlockTable>  <br/><br/>
        <div style="position:relative;left:75px;">
             <apex:commandButton value="Create" action="{!processselected}"  />

<apex:outputPanel id="thePageBlock">
<apex:pageblocksection title="Attributes for {!pp}">
    <apex:pageblocksection columns="2">
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Condition_1__c}" required="false"/>
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Condition_2__c}" required="False"/>
        <apex:inputHidden />
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Condition_3__c}" required="false"/>
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Shape_1__c}" required="false"/>
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Shape_2__c}" required="False"/>
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Capacity__c}" required="false"/>
        <apex:inputHidden />
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Size__c}" required="false"/>
        <apex:inputHidden />
        <apex:inputfield value="{!Customer_Product_Line_Item__c.Additional_Information__c}" required="false"/>
        <apex:inputHidden />



public class AddCustomerProductStage1vfhide1{

/* Constructor Function. The CustomerProduct id is captured in this function */

public Customer_Product_Line_Item__c cpl {get;set;}
public Opportunity o;
public String pp {get;set;}
public AddCustomerProductStage1vfhide1(ApexPages.StandardController c)
            o = [select id from Opportunity where id =

      public Opportunity getOpportunity() {
            return o;

/* Variable declarations */

public List<cCustomer> cpList {get; set;}                              // Wrapper class which stores customer product data and a boolean flag.
public List<cCustomer> cpsel{get; set;}
public ID oid {get; set;}

public String userinput ='' ;                                                               // cp Name
public String userinp;  

Public List<Customer_Product__c> results = new List<Customer_Product__c>();                 // Customer_Product__c search results.

Public List<Customer_Product__c> selproduct = new List<Customer_Product__c>();                 // Customer_Product__c selectedproduct.

/* End of Variable declarations */

/* Getter and setter methods for getting the user input ie. Customer_Product__c name from the UI */

public String getuserinput(){return userinput;}
public void setuserinput(String userinp1)

public String getselproduct(){return null;}

/*End of Getter and Setter methods */

/* Method to Search the Customer_Product__c database to return the query results */
public List<Customer_Product__c> cpsearch()
     cpList = new List<cCustomer>();
     for(Customer_Product__c c : [select id, name from Customer_Product__c where Name like :userinput+'%' order by Name asc])
      cCustomer c1=new cCustomer(c);
       //  cpList.add(new cCustomer(c));
 { getuserinput();
return null;
/* End of method */

/* Method for returning the Customer Product search results to the UI */
public List<cCustomer> getresults()
  return cpList; 

    public PageReference processSelected() {

         //We create a new list of Customer Products that we be populated only with Customer Products if they are selected
        List<Customer_Product__c> selectedProduct = new List<Customer_Product__c>();
        //We will cycle through our list of cCustomer and will check to see if the selected property is set to true, 
        //if it is we add the Customer Product to the selectedProduct list
        for(cCustomer cCon : getresults()) {
            if(cCon.selected == true) {
        // Now we have our list of selected products and can perform any type of logic we want
        System.debug('These are the selected Products...');
        for(Customer_Product__c cCon : SelectedProduct ) {

    cpsel = new List<cCustomer>();
     for(Customer_Product__c p : [select name from Customer_Product__c where id =:selproduct])
     cpsel.add(new cCustomer(p));
     }return null;


/* Wrapper class to contain customer product record and a boolean flag */
public class cCustomer{
public Customer_Product__c con {get; set;}
public Boolean selected {get; set;}

public cCustomer (Customer_Product__c c)
     con = c;
     selected = false;

/* end of Wrapper class */    




You need to use the rerender attribute on the commandButtons to specify what parts of the page need to be refreshed for each action.