3

Continue solving this problem, I've replaced Mojarra by MyFaces and upgrade JDK and when I continue working on form after restart of server, following error appears:

An Error Occurred:

/food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml

Caused by:
javax.faces.application.ViewExpiredException - /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml

Console:

SEVERE: Exception loading sessions from persistent storage
java.lang.IllegalStateException: unread block data
    at java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:2376)

Stack Trace:

javax.faces.application.ViewExpiredException: /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
    at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128)
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

And my web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         id="WebApp_ID" version="3.0">

  <display-name>PORTAL</display-name>
  <session-config>
    <session-timeout>180</session-timeout>
  </session-config>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.xhtml</welcome-file>
    <welcome-file>index.htm</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>

  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
  </context-param>

</web-app>

Don't you ever met such error report?

Community
  • 1
  • 1
gaffcz
  • 3,469
  • 14
  • 68
  • 108
  • @BalusC: Yes, mojarra. I've "solved" it using redirection servlet. I'm redirecting application to `error.xhtml` page with some report ("server is restarted") if one of 403/404/500 errors is occured. It's not a solution of `@ViewScoped` problem but it's enough for me... – gaffcz Jun 30 '11 at 12:35

5 Answers5

5

This might be a bit late to reply, but I had the same problem and I spent quite some time to solve it. So, I thought this might help someone else.

By default, MyFaces does serialization of state, even when state is being saved on the server, while Mojarra does not. So, if you have some beans that are not serializable, or which are using other beans that are not serializable, you will see that error (the server is not able to serialize the object).

You can disable the serialization so MyFaces will work like Mojarra. Check this link: ViewScoped Bean cause NotSerializableException

Community
  • 1
  • 1
mist
  • 51
  • 1
  • 1
3

The problem you are experienced here is typical, and is caused because by default MyFaces generates a random secret for encode the view state. Each time the server restart, a new random secret is generated.

To solve this, you need to setup some web config params, specially org.apache.myfaces.SECRET and org.apache.myfaces.MAC_SECRET, so the same secret is used each time your server is restarted. Mojarra has something similar too, but I don't remember the param name at this moment.

Check this page Secure Your Application with MyFaces. There you can find all details you need to setup your encryption.

You can send questions about MyFaces by subscribing to Users and Dev Mailing Lists

neni
  • 813
  • 5
  • 16
  • 34
lu4242
  • 2,318
  • 1
  • 15
  • 15
  • Thank you, so I'll try to find the mojarra solution :) – gaffcz Jul 11 '11 at 05:17
  • I've tried to use myfaces (instead of mojarra) with all of secret staff you're speaking about, but the last result was something like `Illegal key size` exception. And when I've used `SECRET` and `MAC_SECRET` params only, it throws `invalid key length`... – gaffcz Jul 11 '11 at 16:24
  • That exception occur usually because you have to generate a key that match your encryption algorithm. Look on this folder [State Encryption Tests](http://svn.apache.org/repos/asf/myfaces/shared/trunk/core/src/test/java/org/apache/myfaces/shared/util). There are some junit tests with valid keys and params combinations. Note you have to generate your own keys for your production environment. – lu4242 Jul 11 '11 at 19:38
  • Can anybody confirm this solution solves the problem? It does not for me on Liberty Profile 8.5.5.8. Thanks. – icordoba Jan 26 '16 at 14:48
3

As said, on the other answer, one need to define the SECRET. I followed the instructions at Secure_Your_Application. I added the below lines to web.xml (change the secrets accordingly). And dont forget to the to download the unlimited strength JCE policy files.

<context-param>
  <param-name>org.apache.myfaces.ALGORITHM</param-name>
  <param-value>AES</param-value>
</context-param>
<!-- Defines the secret (Base64 encoded) used to initialize the secret key
     for encryption algorithm. The size of it depends on the algorithm used for encryption -->
<context-param>
  <param-name>org.apache.myfaces.SECRET</param-name>
  <param-value>MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIz</param-value>
</context-param>
<!-- Define the initialization code (Bas64 encoded) that are used to initialize the secret key used
     on the Message Authentication Code algorithm. The size of it depends on the algorithm used for mac calculation -->
<context-param>
  <param-name>org.apache.myfaces.MAC_SECRET</param-name>
  <param-value>YWJjZDEyMzQ=</param-value>
</context-param>
Leonel Martins
  • 2,713
  • 1
  • 21
  • 24
  • Thank you, I'm using mojarra now and the `com.sun.faces.config.ConfigureListener` doesn't help :( – gaffcz Mar 17 '12 at 06:41
  • Indeed, this change didnt solved my problem. My mistake. I edited my question with actual testing made. ;-) Now, using @lu4242 suggestion, it works fine. – Leonel Martins Mar 27 '12 at 00:35
  • lu4242's advise is working for myfaces, so I should accept his answer.. but what about mojarra? ;-)) – gaffcz Mar 27 '12 at 05:48
  • i'll make a project with mojarra and try to solve it. i'll post what i find here. – Leonel Martins Apr 13 '12 at 00:41
0

SOLUTION: I had to consider which classes should be serializabled and which not.

gaffcz
  • 3,469
  • 14
  • 68
  • 108
0

I usually get this error. I am using myfaces 1.2 and websphere 7, but then I did not restart the server. I first stopped the server, then started again rather than doing a restart. That worked.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52