I currently have a radio select that when the user selects a value re-renders an apex:pageblocksection(Usage Estimator) to enable some input fields in it (based on the screenshot below).
The problem is when I've selected a value for each radio select field, it renders the section and puts a defualt "0" value on the other fields on that section as per screenshot.
Steps:
- Select a Gas value,which renders the section to enable Gas row fields(set of fields screenshot above)
- Select an Electricity value, which renders the section to enable Electricity row fields(set of fields screenshot above),but then changes the values of the gas row fields with "0"
Am I doing something wrong with rerendering the section?
Here are the snippets from the visualforce page and extension class:
VF Page
<!--ELECTRICITY Radio Button-->
<apex:selectRadio value="{!selectedElecICP}" layout="pageDirection" rendered="{!elecICPList.size > 0}">
<apex:actionsupport action="{!searchICPElecServicesDetails}" event="onchange"
reRender="icpelecdetailpanel,econs,estimators"
status="waitStatus"/>
<apex:selectOptions value="{!ElecItems}"/>
<!--GAS Radio Button-->
<apex:selectRadio value="{!selectedGASICP}" layout="pageDirection" rendered="{!gasICPList.size > 0}">
<apex:actionsupport action="{!searchICPGasServicesDetails}" event="onchange"
reRender="gasdetailpanel,gcons,estimators"
status="waitStatus"/>
<apex:selectOptions value="{!GasItems}"/>
<!--Usage Estimators pageblocksection-->
<apex:pageBlockSection title="Usage Estimator" columns="4" id="estimators">
<apex:selectList size="1" id="estBy" value="{!estimateBy}" label="Estimate By" disabled="{!IF(selectedElecICPDetail==null && selectedGasICPDetail==null, true ,false)}">
<!--apex:selectOption itemValue="EAC" itemLabel="per Annum"/-->
<apex:selectOption itemValue="Period" itemLabel="per Period"/>
<apex:selectOption itemValue="Questions" itemLabel="by Questions"/>
<apex:actionsupport event="onchange" reRender="estimators" action="{!resetUsageCalculation}"/>
</apex:selectList>
<apex:inputCheckbox label="Override" >
</apex:inputCheckbox>
<apex:outputText ></apex:outputText>
<apex:outputText ></apex:outputText>
<!--Electricity-->
<apex:inputText label="day/s" disabled="{!IF(selectedElecICPDetail==null,true,false)}" id="numDaysE" value="{!numberOfDaysE}"/>
<apex:inputText label="kWh" disabled="{!IF(selectedElecICPDetail==null,true,false)}" id="consE" value="{!totalConsumptionE}"/>
<apex:inputText label="Electricity" value="{!elecConsumption}" id="econs" disabled="{!IF(selectedElecICPDetail==null,true,false)}" html-placeholder="kWh"/>
<apex:pageBlockSectionItem>
<apex:image value="{!elecUsageImgURL}" rendered="{!elecConsumption != null}" height="25px" width="25px"/>
</apex:pageBlockSectionItem>
<!--Gas-->
<apex:inputText label="day/s" disabled="{!IF(selectedGasICPDetail==null,true,false)}" id="numDaysG" value="{!numberOfDaysG}" />
<apex:inputText label="kWh" disabled="{!IF(selectedGasICPDetail==null,true,false)}" id="consG" value="{!totalConsumptionG}" styleClass="slds-input"/>
<apex:inputText label="Gas" value="{!gasConsumption}" id="gcons" disabled="{!IF(selectedGasICPDetail==null,true,false)}" html-placeholder="kWh"/>
<apex:pageBlockSectionItem>
<apex:image value="{!gasUsageImgURL}" rendered="{!gasConsumption != null}" height="35px" width="35px"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
Extension class
//Consumption variables
public decimal elecConsumption {get; set;}
public decimal gasConsumption {get; set;}
public decimal lpgConsumption {get; set;}
//Estimate by Period variables
public integer numberOfDaysE {get; set;}
public integer numberOfDaysG {get; set;}
public integer numberOfDaysL {get; set;}
public decimal totalConsumptionE {get; set;}
public decimal totalConsumptionG {get; set;}
public decimal totalConsumptionL {get; set;}
public PageReference searchICPElecServicesDetails(){
elecConsumption = null;
if(selectedElecICP != 'None') {
//selectedElecICPDetail = mapICPElecSummary.get(selectedElecICP);
SearchICPRegistryService.ICP_element icp = new SearchICPRegistryService.ICP_element();
icp.type_x = 'ELECTRICITY';
icp.ICPIdentifier = selectedElecICP;
SearchICPRegistryService.icpDetail_element icpDetail = new SearchICPRegistryService.icpDetail_element();
icpDetail.searchOtherRegistry = false;
icpDetail.ICP = icp;
SearchICPRegistryService.searchICPRegistryRequest_element regReq = new SearchICPRegistryService.searchICPRegistryRequest_element();
regReq.icpDetail = icpDetail;
showICPElectricSummary = true ;
selectedElecICPDetail = searchICPDetailRegistryService(regReq,'ELECTRICITY');
} else {
showICPElectricSummary = false;
selectedElecICPDetail = null;
totalConsumptionE = null;
numberOfDaysE = null;
}
return null ;
}
public PageReference searchICPGasServicesDetails(){
gasConsumption = null;
if(selectedGASICP != 'None') {
SearchICPRegistryService.ICP_element icp = new SearchICPRegistryService.ICP_element();
icp.type_x = 'GAS';
icp.ICPIdentifier = selectedGASICP;
SearchICPRegistryService.icpDetail_element icpDetail = new SearchICPRegistryService.icpDetail_element();
icpDetail.searchOtherRegistry = false;
icpDetail.ICP = icp;
SearchICPRegistryService.searchICPRegistryRequest_element regReq = new SearchICPRegistryService.searchICPRegistryRequest_element();
regReq.icpDetail = icpDetail;
showICPGasSummary = true;
selectedGasICPDetail = searchICPDetailRegistryService(regReq,'GAS');
} else {
showICPGasSummary = false;
selectedGasICPDetail = null;
totalConsumptionG = null;
numberOfDaysG = null;
}
return null ;
}