You need to sign in to do that
Don't have an account?
stan_sfdc
Passing Input Text Values from VF Page in Wrapper
I have two problems here -
1. When invoking Save, the value of Input Text of "Broadcast Number" is not getting sent to the controller, without removing the <apex:selectList>
2. When click on Next / Previous Page (in pagination); the values are getting reset
VF Page
Class
1. When invoking Save, the value of Input Text of "Broadcast Number" is not getting sent to the controller, without removing the <apex:selectList>
2. When click on Next / Previous Page (in pagination); the values are getting reset
VF Page
<apex:page standardController="Commercial__c" extensions="CommercialSchedulerVFPController"> <apex:form id="myform"> <apex:sectionHeader subtitle="{!titleValue}" title="Commercial Scheduler"/> <!-- Commercial Details Section --> <apex:pageBlock id="detailsBlock" title="Commercial Details"> <apex:pagemessages /> <apex:pageBlockButtons location="top"> <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!doCancel}" value="Cancel" immediate="true"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Commercial Details" columns="2"> <apex:inputField value="{!commercialObj.Name}" required="true"/> <apex:inputField value="{!commercialObj.Running_Time_Seconds__c}" required="true"/> <apex:inputField value="{!commercialObj.Account__c}"/> <apex:inputField value="{!commercialObj.Contracted_Broadcast_Time_Seconds__c}" required="true"/> <apex:inputField value="{!commercialObj.Broadcast_Start_Date__c}" required="true"/> <apex:outputField value="{!commercialObj.Total_Broadcast_Time_Seconds__c}"/> <apex:inputField value="{!commercialObj.Broadcast_Stop_Date__c}" required="true"/> <apex:outputField value="{!commercialObj.Broadcasts_Scheduled__c}"/> </apex:pageBlockSection> <!-- Broadcast Chart Section --> <apex:pageBlockSection title="Broadcast Chart" columns="1"> <apex:chart name="AnnualRecurringRevenue" data="{!TimeSlotResults}" width="100%" height="200" > <apex:axis type="Numeric" position="left" grid="true" title="Seconds" fields="broadcastNumber" steps="10"> <apex:chartLabel /> </apex:axis> <apex:axis type="Category" position="bottom" grid="false" title="Date" fields="broadcastNumber"> <apex:chartLabel /> </apex:axis> <apex:barSeries orientation="vertical" axis="left" stacked="false" xField="broadcastNumber" yField="broadcastNumber"> </apex:barSeries> </apex:chart> </apex:pageBlockSection> <!-- Timeslots Section --> <apex:pageBlockSection id="pbTimeslot" title="Timeslots" columns="1"> <apex:selectList id="selectId" value="{!programGenreValue}" size="1"> <apex:actionSupport event="onchange" action="{!getResults}" /> rerender="pbTimeslot,detailsBlock" <apex:selectOptions value="{!programGenre}"/> </apex:selectList> <apex:pageBlockTable id="maintable" value="{!timeSlotResults}" var="t" rendered="{!NOT(ISNULL(timeSlotResults))}" width="100%"> <apex:column width="20%" headerValue="Number of Broadcasts"> <apex:outputPanel styleClass="requiredInput" layout="block"> <apex:outputPanel styleClass="requiredBlock" layout="block"/> <apex:inputText value="{!t.broadcastNumber}" style="width:50px"/> </apex:outputPanel> </apex:column> <apex:column width="20%" headerValue="Program Name"> <apex:outputLink value="/{!t.timeSlotObj.Id}" target="_blank"> <apex:outputText value="{!t.timeSlotObj.Program_Name__c}"> </apex:outputText> </apex:outputLink> </apex:column> <apex:column width="20%" value="{!t.timeSlotObj.Program_Genre__c}" headerValue="Program Genre"/> <apex:column width="20%" value="{!t.timeSlotObj.Timeslot_Date_Time__c}" headerValue="Timeslot Date/Time"/> <apex:column width="20%" value="{!t.timeSlotObj.Remaining_Commercial_Time_Seconds__c}" headerValue="Remaining Commercial Time (Seconds)"/> </apex:pageBlockTable> <apex:outputPanel > <div align="center"> <apex:commandButton disabled="{!!hasprevious}" action="{!First}" value="|< First" immediate="true"/> <apex:commandButton disabled="{!!hasprevious}" action="{!Previous}" value="Previous" immediate="true"/> <apex:outputText >{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText> <apex:commandButton disabled="{!!hasnext}" action="{!Next}" value="Next" immediate="true"/> <apex:commandButton disabled="{!!hasnext}" action="{!Last}" value="Last >|" immediate="true"/> </div> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Class
public class CommercialSchedulerVFPController{ public Commercial__c commercialObj {get;set;} public Integer noOfRecords {get; set;} public Integer noOfBroadcasts {get;set;} public String programGenreValue {get;set;} public ApexPages.StandardSetController con{get;set;} public DateTime startDate; public DateTime endDate; public Integer size {get;set;} public String commercialObjId {get;set;} public String titleValue {get;set;} List<TimeSlotWrapper> timeSlotResults {get;set;} // Standard Constructor public CommercialSchedulerVFPController(ApexPages.StandardController controller){ this.commercialObj = (Commercial__c)controller.getRecord(); commercialObjId = ApexPages.currentPage().getParameters().get('id'); programGenreValue = ''; size = 5; if(commercialObjId == Null || commercialObjId == ''){ // Represents a New Page commercialObj = New Commercial__c(); titleValue = 'New Commercial'; initStdSetController(); } else{ // Represents an existing Edit Page commercialObj = [SELECT Id,Name,Running_Time_Seconds__c,Account__c,Contracted_Broadcast_Time_Seconds__c,Broadcast_Start_Date__c,Total_Broadcast_Time_Seconds__c,Broadcast_Stop_Date__c,Broadcasts_Scheduled__c FROM Commercial__c WHERE id=:commercialObjId ]; titleValue = commercialObj.Name; Map<Id,Double> timeSlotBroadcastNoMap = fetchExistingTimeslotValue(); initStdSetController(); } } public void initStdSetController(){ // Change these dates to actuals startDate = Date.today(); endDate = Date.today()+14; con = new ApexPages.StandardSetController(Database.getQueryLocator(getQuery())); con.setPageSize(size); noOfRecords = con.getResultSize(); } // Method to do a dynamic query based on the selected Genre private String getQuery(){ // Change these dates to actuals startDate = Date.today(); endDate = Date.today()+14; String query = 'SELECT Timeslot_Date_Time__c, Remaining_Commercial_Time_Seconds__c, Program_Name__c, Program_Genre__c' + ' FROM Timeslot__c'; // + ' WHERE Timeslot_Date_Time__c >=:Startdate and Timeslot_Date_Time__c <=:Enddate'; system.debug('@@ programGenreValue @@'+programGenreValue); if(programGenreValue!='' && programGenreValue!='All'){ query += ' WHERE Program_Genre__c =: programGenreValue '; } System.debug('@@ query @@ '+query); return query; } // This method is used to invoke the list from the VF Page public pageReference getResults(){ system.debug('@@ getResults - Start @@'); initStdSetController(); system.debug('@@ getResults - End @@'); return null; } // Methods used for pagination logic public Boolean hasNext { get { return con.getHasNext(); } set; } // indicates whether there are more records before the current page set. public Boolean hasPrevious { get { return con.getHasPrevious(); } set; } // returns the page number of the current page set public Integer pageNumber { get { return con.getPageNumber(); } set; } // returns the first page of records public void first() { con.first(); } // returns the last page of records public void last() { con.last(); } // returns the previous page of records public void previous() { con.previous(); } // returns the next page of records public void next() { system.debug('@@ con @@'+con); for (TimeSlotWrapper loopvar : timeSlotResults) { system.debug('@@ timeSlotResults-loopvar @@'+loopvar); } con.next(); } // returns the PageReference of the original page, if known, or the home page. public void cancel() { con.cancel(); } // This method will Cancel the transaction and redirect to the Object Page without validations public Pagereference doCancel(){ Schema.Describesobjectresult result = Schema.Sobjecttype.Commercial__c; ApexPages.Pagereference cancelPg = new PageReference('/' + result.getKeyPrefix() + '/o'); cancelPg .setRedirect(true); return cancelPg ; } // This method constructs the picklist of Program Genre used for filtering the table public List<SelectOption> getProgramGenre(){ List<SelectOption> options = new List<SelectOption>(); Schema.DescribeFieldResult fieldResult = Timeslot__c.Program_Genre__c.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); options.add(new SelectOption('All','All')); // Reading from the object definition to allow dynamic values to be added later for(Schema.PicklistEntry f : ple){ options.add(new SelectOption(f.getLabel(), f.getValue())); } system.debug('@@ options @@'+options); return options; } // Fetch existing value of Timeslots for existing public Map<Id,Double> fetchExistingTimeslotValue(){ system.debug('@@ fetchExistingTimeslotValue - Start @@'); Map<Id,Double> timeSlotBroadcastNoMap = new Map<Id,Double>(); List<Commercial_Slot__c> commercialSlotList = [SELECT Timeslot__c, Number_of_Broadcasts__c, Commercial__c FROM Commercial_Slot__c WHERE Commercial__c =: commercialObj.Id ]; for(Commercial_Slot__c loopvar: commercialSlotList){ timeSlotBroadcastNoMap.put(loopvar.Timeslot__c, loopvar.Number_of_Broadcasts__c); } system.debug('@@ timeSlotBroadcastNoMap @@'+timeSlotBroadcastNoMap); system.debug('@@ fetchExistingTimeslotValue - End @@'); return timeSlotBroadcastNoMap; } // Invokes the Save operation public PageReference save(){ system.debug('@@ save - Start @@'); for (TimeSlotWrapper loopvar : timeSlotResults) { system.debug('@@ loopvar @@'+loopvar); //if (cw.checked) // selectedContacts.add(new ContactListWrapper(cw.serviceContractNotificationObj)); //else // unselectedContacts.add(new ContactListWrapper(cw.serviceContractNotificationObj)); } system.debug('@@ save - End @@'); return null; } // This is to capture which numbers were entered i.e. changed the default from 0 to something else public List<TimeSlotWrapper> changedTimeSlotRecords { get { if (changedTimeSlotRecords == null) changedTimeSlotRecords = new List<TimeSlotWrapper>(); return changedTimeSlotRecords; } set; } public List<TimeSlotWrapper> getTimeSlotResults() { timeSlotResults = new List<TimeSlotWrapper>(); for (Timeslot__c loopvar : (List<Timeslot__c>)con.getRecords()){ timeSlotResults.add(new TimeSlotWrapper(loopvar)); } system.debug('@@ timeSlotResults @@'+timeSlotResults); return timeSlotResults; } // Wrapper Class to hold the Number of Broadcast Schedules public class TimeSlotWrapper { public Integer broadcastNumber {get; set;} public Timeslot__c timeSlotObj { get; set;} public TimeSlotWrapper(){ timeSlotObj = new Timeslot__c(); broadcastNumber = 0; } public TimeSlotWrapper(Timeslot__c t){ timeSlotObj = t; broadcastNumber = 0; } } }
Also, because of the standardsetcontroller, your wrappered results are getting cached. So when you hit previous / next, it's loading the old state of the record. You'll either need to requery (and reset) the standardsetcontroller or use a different approach in order to get the most current value of your records.
All Answers
Also, because of the standardsetcontroller, your wrappered results are getting cached. So when you hit previous / next, it's loading the old state of the record. You'll either need to requery (and reset) the standardsetcontroller or use a different approach in order to get the most current value of your records.