You need to sign in to do that
Don't have an account?
Controller Setter Not Called
I have an Apex page that displays fields from a structured bean returned from my controller using custom components:
<apex:form >
<apex:variable var="bean" value="{!ResponseDetail}">
<apex:datalist var="fragment" value="{!bean.fragments}" type="1">
<c:ResponseWidget fragment="{!fragment}" />
<br />
</apex:datalist>
<apex:commandButton value="Update" action="{!updateSurvey}" />
</apex:variable>
</apex:form>
The controller has an instance variable with getter and setter:
public SurveyBean ResponseDetail {
get {
...
return new SurveyBean(...);
}
set;}
public PageReference updateSurvey() {
if (ResponseDetail.fragments != null)
return null;
return null;
}
The page displays fine, but when I press the update button I get a null pointer exception. The setter is not being called before the update method as the documentation suggests. What am I doing wrong?
Jeff
It was. I modified the getter to only set it if null and now it seems to work correctly:
if (ResponseDetail == null) {
...
ResponseDetail = new SurveyBean(...);
}
return ResponseDetail;
Not yet obvious to me why this is the case, but thanks!
Jeff
All Answers
It was. I modified the getter to only set it if null and now it seems to work correctly:
if (ResponseDetail == null) {
...
ResponseDetail = new SurveyBean(...);
}
return ResponseDetail;
Not yet obvious to me why this is the case, but thanks!
Jeff
Ah, ok. How to explain my next roadblock?
The SurveyBean contains a list of SurveyFragments and they contain a ResponseBean object. When my VF page elaborates the SurveyBean it invokes custom components which, ultimately, render the survey as a list of input widgets. Here's one:
<apex:component >
<apex:attribute name="fragment" description="This is the fragment for the component"
type="SurveyFragment" required="true"/>
<apex:outputText >{!fragment.firstResponse.question}</apex:outputText><br />
<em>{!fragment.sInstructions}</em><br />
<apex:inputText value="{!fragment.firstResponse.score}" title="Score"/><br />
<em>{!fragment.cInstructions}</em><br />
<apex:inputTextarea value="{!fragment.firstResponse.comment}" cols="80" title="Comment"/><br />
</apex:component>
Now, when the SurveyBean gets back to my controller, none of the values which were set into its ResponseBeans are available. They all have null values. I know the SurveyBean is getting updated correctly, because it has a single checkbox widget and its state is being transmitted to the controller. Where are the other values going?
Jeff