The documentation says that using the transient
keyword on properties will keep them out of the view state, but my testing seems to show otherwise. How can I exclude this property from the view state?
Example of smallest view state (0.86kb internal):
// ViewStateProblems.cls
public class ViewStateProblems {
}
// ViewStateProblems.page
<apex:page controller="ViewStateProblems">
<apex:form ></apex:form> <!-- remove the form and view state goes away -->
</apex:page>
Example showing a table of records with no view state (0kb):
// ViewStateProblems.cls
public class ViewStateProblems {
public List<Case> getCases(){
return [select CaseNumber, OwnerId, ContactId from Case limit 1000];
}
}
// ViewStateProblems.page
<apex:page controller="ViewStateProblems">
<apex:pageBlock >
<apex:pageBlockTable value="{!cases}" var="c">
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.OwnerId}"/>
<apex:column value="{!c.ContactId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Turning on view state by just adding a form to the page. Note, my cases
object is not in the form tags (internal view state of 26.02):
// ViewStateProblems.cls
public class ViewStateProblems {
public List<Case> getCases(){
return [select CaseNumber, OwnerId, ContactId from Case limit 1000];
}
}
// ViewStateProblems.page
<apex:page controller="ViewStateProblems">
<apex:pageBlock >
<apex:pageBlockTable value="{!cases}" var="c">
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.OwnerId}"/>
<apex:column value="{!c.ContactId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:form> maybe create new case here </apex:form>
</apex:page>
Picture of view state (I don't yet sufficient karma to upload photos): http://cl.ly/image/1N183P2C3D3W
Here I make a version using the transient
keyword on the cases
property but it has no effect on the view state size (internal view state of 26.02):
// ViewStateProblems.cls
public class ViewStateProblems {
public transient List<Case> cases {get; private set;} {
cases = [select CaseNumber, OwnerId, ContactId from Case limit 1000];
}
}
// ViewStateProblems.page
<apex:page controller="ViewStateProblems">
<apex:pageBlock >
<apex:pageBlockTable value="{!cases}" var="c">
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.OwnerId}"/>
<apex:column value="{!c.ContactId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:form> maybe create new case here </apex:form>
</apex:page>
Shouldn't that example using the transient
keywork have had the same internal view state size as the first form example of only 0.86kb? If not, how can I stop the cases
property from being sent in view state?