myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deryk Sinotte <>
Subject Questions about using StateManager.getViewState() in MyFaces 2
Date Wed, 27 Jul 2011 18:41:35 GMT
I was hoping someone could provide some guidance about using 

Without getting into a lot of historical details, we have a legacy 
FormRenderer that needs to include the ViewState in a hidden field.  
I've tried to use the following call to get current ViewState value:

String viewState = 

What seems to happen with MyFaces (I'm currently working off the latest 
2.1 trunk), is that, during the render phase, when the first form on the 
page is being rendered, this call triggers a full save of the current 
state of the component tree and returns the appropriate ViewState 
value.  In other words, the first time I call this, it works how I would 

However, if I have multiple forms on the page, each form makes the same 
call but the full state saving logic is no longer triggered.  From what 
I can tell, the first call does the full state save and then caches it 
and simply returns the ViewState value for subsequent calls.

The problem this poses is that the state of our components are not 
finalized during that first call.  There are more forms and component to 
render and the state of some of these has not been completely set yet.  
Since future calls only return the cached ViewState value and do not do 
a full state save, some of our components fail to behave properly when 
an subsequent Ajax request is made because their state is not full saved.

My questions are:

1) Have I characterized the behaviour correctly?
2) Is there a way to force a full state save to occur after the intial 
call to getViewState()?


View raw message