You need to sign in to do that
Don't have an account?
Visualforce page loses field value when refreshing
I am displaying a datatable for a wrapper class that includes a "Selected" checkbox and a custom object, Oppdoc__c. There is a datetime input box(bound to custom object Query__c to use the date picker gadget), and I want to display the records that have CreatedDate greater than or equal to the datetime input. This works, enter a datetime and hit the Refresh button, and the list updates.
I also have a Select All checkbox, and if clicked, it should check or uncheck all the boxes currently in the table. However, if this is checked, it resets the entire table to the default state, ignoring the query field. It seems as though the apex code is losing the value of the Query object when SelectAll is invoked. Here is my code:
Controller:
public class OppDocTricks { private static OppDoc__c doc; private static Shipment__c shp; private static String pagebreakstring = 'page-break-after: always;'; private static Integer maxdocs; private static Query__c tempq; //to use for query info / date picker private static boolean IsAllSelected = false; private static list<xdoc> displaylist {get;set;} public static Query__c getQuery() { if (tempq == null){ system.debug('resetting tempq right now'); tempq = new Query__c(); } if (tempq.After_Date__c == null) tempq.After_Date__c = datetime.now().adddays(-90); return tempq; } public static void setQuery(Query__c q) { tempq = q; } public boolean getIsAllSelected() { return IsAllSelected; } public void setIsAllSelected(Boolean AllSelected){IsAllSelected = AllSelected;} public OppDocTricks() { if (ApexPages.currentPage().getParameters().get('id') != null) doc = [select id, name from OppDoc__c where id = :ApexPages.currentPage().getParameters().get('id')]; } public class xdoc { OppDoc__c d; boolean Selected; public xdoc( OppDoc__c oppdoc) { d=oppdoc;} public OppDoc__c getOppDoc() { return d; } public boolean getSelected() { return Selected; } public void setSelected(boolean sb) { Selected = sb; } } public static list<xdoc> getQueryinvs() { map<String, id> rtmap = new map<String, id>(); util.mapRecordTypes(rtmap, 'OppDoc__c'); tempq = getQuery(); system.debug('tempq '+ tempq.After_Date__c); if (displaylist != null){ for (xdoc x : displaylist){ system.debug('xd ' + x.d.CreatedDate); } } if (displaylist == null){ displaylist = new list<xdoc>(); for (OppDoc__c odoc : [select CreatedDate, Status__c, Shipto_Name__c, ShiptoZip__c, ShiptoState__c, ShiptoLine2__c, ShiptoLIne1__c, ShiptoCountry__c, ShiptoCity__c, Shipping_Address__c, Purchase_Total__c, Purchase_Order__c, Name, DueDate__c, Document_Notes__c, Date__c, Current_Due_Total__c, Current_Due_Subtotal__c, BilltoZip__c, BilltoState__c, BilltoName__c, BilltoLine2__c, BilltoLine1__c, BilltoCountry__c, BilltoCity__c, Accounting_Entry_Total__c, opportunity__r.Hope_Order_Number__c, opportunity__r.Opportunity_Number__c, Opportunity__r.Name, (select Name, Type__c, Total_Amount__c, Purchase_Quantity__c, Purchase_Net_Amount__c, Product_Code__c, Entry_Date__c, Description__c, Currently_Due__c From Line_Items__r) from OppDoc__c where recordtypeId = :rtmap.get('Invoice') and CreatedDate >= :tempq.After_Date__c]) { system.debug('newxdoc created ' + odoc.CreatedDate); xdoc newxdoc = new xdoc(odoc); //newxdoc.Selected = true; displaylist.add(newxdoc); } }else{//(must not be null) for (Integer counter = 1; counter == displaylist.size(); counter++){ system.debug('counter ' + counter + ' qinv ' + displaylist[counter].d.CreatedDate); if (displaylist[counter].d.CreatedDate < tempq.After_Date__c){ displaylist.remove(counter); } } } return displaylist; } public static void RefreshQuery() { displaylist = null; system.debug('tempq ' + tempq); } public void SelectAll() { system.debug('selectall anyone? isallselected is ' +IsAllSelected); for (xdoc d : displaylist) { system.debug('d selected before ' + d.Selected); d.SetSelected(IsAllSelected); system.debug('d selected after ' + d.Selected); } } }
Visualforce page:
<apex:page controller="OppDocTricks" cache="true" title="OppDoc Query page" > <style> .OppDocTable{ font-size: 12px; text-align: right; padding: 20px; } </style> <apex:form > <apex:pageblock title="Query OppDocs"> <apex:outputpanel id="table"> <apex:datatable styleclass="OppDocTable" value="{!Queryinvs}" var="inv"> <apex:column > <apex:facet name="header" > <apex:inputcheckbox value="{!IsAllSelected}" > <apex:actionSupport rerender="table" event="onclick" action="{!SelectAll}" status="redrawStatus"/> </apex:inputcheckbox> </apex:facet> <apex:inputcheckbox value="{!inv.Selected}"/> </apex:column> <apex:column value="{!inv.OppDoc.CreatedDate}"> <apex:facet name="header"> <apex:actionStatus id="redrawStatus" startText=" (refreshing...)" /> </apex:facet> </apex:column> </apex:datatable> Show Invoices created since: <apex:inputfield value="{!Query.After_Date__c}" /> <apex:commandbutton value="Refresh list" action="{!RefreshQuery}" status="redrawStatus"/> </apex:outputpanel> <br/> </apex:pageblock> </apex:form> </apex:page>
Thanks for your help,
Jeremy Nottingham
Did you ever find solution to it?
I am facing similar kind of problem.
Try this.