You need to sign in to do that
Don't have an account?
ckellie
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 --> <script> function checkAll(cb) { var inputElem = document.getElementsByTagName("input"); for(var i=0;i<inputElem.length;i++)https://c.cs4.visual.force.com/s.gif { if(inputElem[i].id.indexOf("selectLine1")!=-1) inputElem[i].checked = cb.checked; } } </script> <!-- 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}" /> </apex:panelGrid> <!-- End of panelgrid --> <!-- Div to position the commandbutton appropriately --> <div style="position:relative;left:75px;"> <apex:commandButton value="Search" action="{!cpsearch}" /> </div> <!-- 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" status="status"/> </apex:inputCheckbox> <apex:actionStatus startText="applying value..." id="status"/> </apex:outputPanel > </apex:column> <apex:column headervalue="Customer Product"> <apex:outputtext value="{!cp.con.Name}"/> </apex:column> </apex:pageBlockTable> <br/><br/> <div style="position:relative;left:75px;"> <apex:commandButton value="Create" action="{!processselected}" /> </div> </apex:outputpanel> </apex:pageblocksection> <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 /> </apex:pageblocksection> </apex:pageblocksection> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
Class
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 = :ApexPages.currentPage().getParameters().get('oppid')]; } 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) { this.userinput=userinp1; system.debug('*****SFDC-TEST-1**********'+userinput+'='+userinp); } 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); c1.Selected=false; // cpList.add(new cCustomer(c)); cpList.add(c1); } system.debug('*****SFDC-TEST-2**********'+cpList); if(Test.isRunningTest()) { getuserinput(); getopportunity(); getselproduct(); } return null; } /* End of method */ /* Method for returning the Customer Product search results to the UI */ public List<cCustomer> getresults() { if(Test.isRunningTest()) { cpsearch(); } System.debug('$$$$$$$$'+cpList); 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>(); System.debug('%%%%%%%%%%%%'+getresults()); //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()) { System.debug('#####'+cCon.selected); if(cCon.selected == true) { selectedProduct.add(cCon.con); } } if(test.isRunningTest()){ getresults(); } system.debug('*****SFDC-TEST-3**********'+selectedProduct); // 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 ) { system.debug(cCon); selproduct.add(cCon); } system.debug('*****SFDC-TEST-4**********'+selproduct.size()); cpsel = new List<cCustomer>(); for(Customer_Product__c p : [select name from Customer_Product__c where id =:selproduct]) { cpsel.add(new cCustomer(p)); pp =p.name; }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.