0

I found a lot of articles to @ViewScoped and java.io.NotSerializableException but nothing helped in my case. Perhaps because I am using CDI @ViewScoped and most older questions are about @ManagedBean. Reproduction:

I have a presentation model with following annotation:

@javax.inject.Named
@javax.faces.view.ViewScoped
public class WishPM implements Serializable{ 
[...]
}

Deploying works fine. Also when I access the page using this PM all is fine. But when redeploy the project now after changing something I get:

INFO:   Cannot serialize session attribute   com.sun.faces.application.view.activeViewContexts for session ad1a37e9cf5e1445cabc04a944e0
java.io.NotSerializableException: org.jboss.weld.bean.ManagedBean
[...]
WARNING:   Unable to restore sessions for web module [/wish] from previous deployment
java.lang.NullPointerException

This is not happening if I use @SessionScoped or @Requestscoped. From other threads I have the tip to set STATE_SAVING_METHOD to server in web.xml. It was not set to client so it should have been the default. But at all I set it:

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>

But still the same error. Can someone help me what to try?

timmornYE
  • 708
  • 2
  • 8
  • 22
  • You're not using CDI `@ViewScoped` because `@javax.faces.view.ViewScoped` is not a CDI annotation. See http://stackoverflow.com/questions/9861144/why-is-my-viewscoped-bean-not-surviving-hcommandbutton?answertab=votes#tab-top – rdcrng Aug 20 '13 at 09:32
  • This is `javax.faces.bean.ViewScoped`. `@javax.faces.view.ViewScoped` is CDI: http://jdevelopment.nl/jsf-22/#1087 – timmornYE Aug 20 '13 at 11:26
  • Sigh, yes, I got mixed up, my apologies. – rdcrng Aug 20 '13 at 11:44
  • 1
    Do you have any `service` class injections inside this class which are not serialized.`@Viewscope` needs to be serialized this is true not only for that annotated bean but for the injections into that bean and any other class used in that `@viewscoped` bean and are using `Spring` or `EJB` for service classes? – SRy Aug 20 '13 at 13:08
  • I had two @Stateless beans injected with @EJB. I set also `implements Serializable` for them, but the error stays the same. – timmornYE Aug 20 '13 at 14:19

1 Answers1

-1

Use

@javax.enterprise.context.SessionScoped

insted

@javax.faces.view.ViewScoped

It should help. Read also: Some important information about CDI

There are no @ViewScope for CDI. It means that there are but as I know it is in JEE7 + JSF 2.2.

Tomek
  • 81
  • 9
  • Also MyFaces CODI and Seam 3 offer @ViewScoped for JSF 2.0/2.1 and soon Omnifaces will offer one as well. – rdcrng Aug 20 '13 at 09:26
  • 2
    I use JSF 2.2 and there is ViewScoped for CDI: http://jdevelopment.nl/jsf-22/#1087 – timmornYE Aug 20 '13 at 11:27
  • Using `SessionScoped` for `ViewScoped` is very extreme. You are loading the session with a whole bunch of values that shouldn't be there. Take a look at : http://showcase.omnifaces.org/cdi/ViewScoped. – blo0p3r Aug 07 '14 at 18:08