You need to sign in to do that
Don't have an account?

View State changes not getting saved?
I've written an action handler method, that modifies my view state (member variable in my controller) and I would like to redisplay the screen to show the changes. Why doesn't this show "Hello World" when a click the button? Am I expecting something outside the design, I've studied the wizard sample and this works due to the fact it seems to be changing pages in the event handler. Thanks for any help.
<apex:page controller="HelloWorldController">
<apex:form>
<apex:pageBlock title="Hello {!$User.FirstName}!">
<apex:inputTextarea></apex:inputTextarea> value="{!message}"/> <p/>
<apex:commandButton action="{!showmessage}" value="Show Message"/>
</apex:pageBlock>
</apex:form>
</apex:page>
public class HelloWorldController
{
String message;
public String getMessage()
{
return message;
}
public PageReference showMessage()
{
message = 'Hello World';
return null;
// Also tried this...no joy either
// return System.currentPageReference();
}
}
Error: Read only property 'HelloWorldController.message
you can correct this by adding:
public void setMessage(String message) {
this.message = message;
}
to your controller.
Message Edited by dchasman on 10-03-2007 09:09 PM
That worked thanks, however my demo was a little to simplistic. This is more representative of what I am trying to do. If I have the getLines method always return null Show Messages works, if it returns a new List it doesn't. Is there some issue here with the serailisation of the view state?
Basically the "Add Line" button doesn't work as I was expecting?
public class HelloWorldController
{
String message;
List<CODADocumentViewStateLine> lines;
public String getMessage()
{
return message;
}
public void setMessage(String value)
{
message = value;
}
public List<CODADocumentViewStateLine> getLines()
{
if(lines==null)
{
lines = new List<CODADocumentViewStateLine>();
lines.add(new CODADocumentViewStateLine());
}
return lines;
}
public PageReference showMessage()
{
message = 'Hello World';
return null;
}
public PageReference addLine()
{
lines.add(new CODADocumentViewStateLine());
return null;
}
}
<apex:form>
<apex:pageBlock title="Hello {!$User.FirstName}!">
<apex:inputText value="{!message}"/><p/>
<apex:commandButton action="{!showmessage}" value="Show Message"/><p/>
<apex:commandButton action="{!addline}" value="Add Line"/><p/>
<apex:dataTable value="{!lines}" rows="50" var="linestmp" styleClass="list" rowClasses="dataRow" onRowMouseOver="hiOn(this);" onRowMouseOut="hiOff(this);">
<apex:column>
<apex:facet name="header"><b>Line</b></apex:facet>
{!linestmp.name}
</apex:column>
<apex:column>
<apex:facet name="header"><b>Description</b></apex:facet>
<apex:inputText value="{!linestmp.description}"/>
</apex:column>
<apex:column>
<apex:facet name="header"><b>Nominal</b></apex:facet>
<apex:inputText value="{!linestmp.nominal}"/>
</apex:column>
<apex:column>
<apex:facet name="header"><b>Product</b></apex:facet>
<apex:inputText value="{!linestmp.product}"/>
</apex:column>
<apex:column>
<apex:facet name="header"><b>Account</b></apex:facet>
<apex:inputText value="{!linestmp.account}"/>
</apex:column>
<apex:column>
<apex:facet name="header"><b>Value</b></apex:facet>
<apex:inputText value="{!linestmp.value}"/>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
(CODADocumentViewStateLine.value in this case). If you change from Double to String you'll be back in business.
This issue has already been fixed in Winter '08.