Meaningless Drivel is fun!*
The moose likes JSF and the fly likes Ajax4JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Ajax4JSF "View State couldn Watch "Ajax4JSF "View State couldn New topic
Author

Ajax4JSF "View State couldn't be restored"error after some minute with no user action

Rico Sager
Greenhorn

Joined: Sep 25, 2008
Posts: 2
I use Ajax4Jsf 1.1.4 (,tiles and i small part of struts) in my JSF application. When there is no user activity on the page for some minutes (15?) and then the user click on the Command link the ajax action isn�t done correctly because the Ajax4Jsf view root is lost.

A combo with the error message "View State couldn't be restored" is displayed and when the user confirms the message a normal request is done. This doesn�t occur because of a normal session timeout (the session timeout is much longer).

What is the reason for this behavoir? Is there something like a internal ajax4jsf (session) timeout? Must the context parameter <session-timeout> in the faces config.xml be declared? What can I do to fix this bug?

Here is a section of my web.xml, which might be interesting.

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
<description>
State saving method: "client" or "server" (= default) See
JSF Specification 2.5.2
</description>
</context-param>

<context-param>
<param-name>
org.apache.myfaces.SERIALIZE_STATE_IN_SESSION
</param-name>
<param-value>false</param-value>
</context-param>

<context-param>
<param-name>
org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
</param-name>
<param-value>3</param-value>
<description>
Only applicable if state saving method is "server" (=
default). Defines the amount (default = 20) of the latest
views are stored in session.
</description>
</context-param>

<context-param>
<param-name>
org.apache.myfaces.COMPRESS_STATE_IN_SESSION
</param-name>
<param-value>false</param-value>
</context-param>

<!-- Ajax4Jsf -->
<filter>
<filter-name>ajax4jsf</filter-name>
<display-name>Ajax4jsf Filter</display-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
<init-param>
<param-name>forceparser</param-name>
<param-value>false</param-value>
</init-param>
</filter>

<!-- Tomahawk -->

<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>
org.apache.myfaces.webapp.filter.ExtensionsFilter
</filter-class>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>20m</param-value>
<description>
Set the size limit for uploaded files. Format: 10 - 10
bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
</description>
</init-param>
</filter>
[ September 25, 2008: Message edited by: Rico Sager ]
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

I was also getting the same error while working with RichFaces. Have you tried extending the session timeout.


My Blog SCJP 5 SCWCD 5
Rico Sager
Greenhorn

Joined: Sep 25, 2008
Posts: 2
I don't set the session timeout parameter in the web.xml, but in my java background code:

session.setMaxInactiveInterval(WebUtils.getHttpSessionTimeout(user.getMandant()));

I can try to set the hard coded parameter in the web.xml and look if it work.

The session timeout I set is much larger than the "view root timeout". After the user has confirmed the error message a normal request is done (but not the supposed action of the original link) and than the user can continue working in his session.

Perhaps there is a internal timeout parameter or a memory problem or something else ... ?
Stas Fedorov
Greenhorn

Joined: May 13, 2008
Posts: 7
This happens because of the StateManager implementation (AjaxStateManager) can't work with states on server - it simply returns null, when trying to restore session, because no mechanism for state saving is implemented there - you can see the code.

You can define another state manager in faces-config.xml, i.e. MyFaces one. He has well working state saving mechanism.

This can be done in the following manner:



This has a draw-back - in time View will also become expired, but the timeout can be configured. I don't remember how...
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi Stas Fedorov

I'm with this problem !!! So...I Put <state-manager>org.apache.myfaces.application.jsp.JspStateManagerImpl</state-manager> and this not fix
Someone could help me ???


Fernando Franzini - Java Blog
 
Consider Paul's rocket mass heater.
 
subject: Ajax4JSF "View State couldn't be restored"error after some minute with no user action