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
code developercode developer 

List value getting reset



Scenario 1:


I am using a Wrapper class to prepare a List<Wrapper> in ctrlr using action function.


When the action function gets invoked, I am able to prepare the List<Wrapper>.


I have declared the  List<Wrapper>. as Controller variable.


Scenario 2:



Upon another ui action(say on click of radio button), am invoking another action function.


In the controller,when I tried to access the List<Wrapper> prepared earlier, I am getting null.


The constructor doesnot get invoked between scenario1 and scenario 2.


Could any one please help me.





I guess you have either used "transient" or "static" keyword to declare the list.

Remove that and you are ready to go.

[Static & Transient variables are not saved in the viewstate and hence are get lost after a http invocation]
code developercode developer

Thanks for your immediate reply Avi.


Am not using any static or transient key word.


Iam using this list in an <apex :repeat>


In the <apex:repeat> am displaying a radio button group.


on click of a radio button am calling another action function(say A()).


In the method A() am trying to use the updated list(i.e trying to get the radio button selected value).


But am getting an empty list..

Can you post the code ?
code developercode developer
<apex:actionFunction id="generateAnnualSections" action="{!prepareAnnualSectionWrapper}" name="generateAnnualSectionsJs" rerender="generateAnnualSectionsPanel" status="ctcDisplayStatus">
            <apex:param id="annualStr" name="annualStr" value=""/>
         <apex:actionFunction id="annualToggle" action="{!displaySectionQues}" name="invokeCtrlAnnualSectionActionJs" rerender="circTCForm,theSec" status="ctcDisplayStatus">
            <apex:param id="secName" name="secName" value=""/>
            <apex:param id="index" name="index" value=""/>

<apex:outputPanel id="generateAnnualSectionsPanel"> <apex:variable id="temp" var="temp" value="{!0}" /> <table id="annualTable" border="0" > <apex:repeat value="{!annualWrapperList}" var="wrapperObj" id="theRepeat"> <apex:outputText rendered="{!AND((MOD(temp, 3) == 0), (temp < annualWrapperList.size))}" value="<tr border=1></tr>" escape="false"/> <td> <table id="innerTable" style=" border:1px;border-spacing: 0;border-collapse: collapse;border-style: solid;" > <center><div style="background-color:#c2e4fe;border-top: 1px solid black;border-right: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;"><apex:outputText value="<b>{!wrapperObj.magName}</b>" escape="false"/></div></center> <apex:panelGrid id="theSec" title="{!wrapperObj.magName}" columns="2" width="100%"> <apex:outputLabel for="fstRadio" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"/> <apex:SelectRadio StyleClass="fontStyleTc" id="fstRadio" value="{!wrapperObj.q1Ans}" onclick="invokeCtrlAnnualSectionAction('annualSection',;"> <apex:selectOption itemLabel="Yes" itemValue="Yes"/> <apex:selectOption itemLabel="No" itemValue="No"/> </apex:SelectRadio> <apex:outputLabel for="thetxtArea" value="xxxxxxxxxxxx" rendered="{!wrapperObj.enableQ2}"/> <apex:inputTextarea id="thetxtArea" StyleClass="fontStyleTc" value="{!wrapperObj.q1Comments}" rendered="{!wrapperObj.enableQ2}"/> <apex:outputLabel for="scndRadio" value="sssssssssssssss"/> <apex:SelectRadio id="scndRadio" StyleClass="fontStyleTc" value="{!wrapperObj.q2Ans}"> <apex:selectOption itemLabel="Yes" itemValue="Yes"/> <apex:selectOption itemLabel="No" itemValue="No"/> </apex:SelectRadio> </apex:panelGrid> </table> </td> <apex:variable var="temp" value="{!temp+1}"/> </apex:repeat> </table> </apex:outputPanel>


Here is the controller

public without sharing class Ctrlr {

public        List<AnnualWrapper>                        annualWrapperList                {get;set;}

public void prepareAnnualSectionWrapper(){

//here am preparing wrapper


 public void displaySectionQues(){
//Here when i try to access list am getting null

 public class AnnualWrapper{
    		public String q1Ans	{get;set;}
    		public String q2Ans	{get;set;}
    		public Boolean enableQ2	{get;set;}
    		public String q1Comments	{get;set;}
    		public String magName {get;set;}


code developercode developer

Apart from that I tried to declare a string variable in ctrlr and


I have initialised it in prepareAnnualSectionWrapper().


I tried to debug the string in displaySectionQues().

Here am getting the string as null..




I am unable to find out, from where you are calling the first actionFunction.


I f you want to access the list prepared from calling the first actionFunction then you have to make sure that the action associated with the earlier actionFunction should  neccessarilly be called before accessing the wrapper list.


The constructor will be called prior to any method, so you must intantiate the annualWrapperList in the constructor.


If you want to make sure that annualWrapperList is populated before you access it from the "displaySectionQues()" method then try calling "prepareAnnualSectionWrapper()" method from the constructor or define it in action attribute of the page.


Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other's benefit.