tags:

views:

70

answers:

1

Hi, I've been banging my head around with a @ViewScoped managed-bean. I'm using primeface's "schedule" component in order to display some events. When the user clicks on a specific button a method in the viewscoped bean is called using ajax but every time I get a "java.io.NotSerializableException", if I change the managed-bean scope to request the problem dissapears.

What am I doing wrong? any ideas?

here is my managed bean :

@ManagedBean(name = "schedule")
@ViewScoped
public class ScheduleMBean implements Serializable {

    @EJB
    private CongeBean congeBean;


    @ManagedProperty(value = "#{sessionBean}")
    private SessionMBean sessionBean;

    private DefaultScheduleModel visualiseurConges = null;

    public ScheduleMBean(){

    }
    @PostConstruct
    public void init() {

        if(visualiseurConges == null){

                visualiseurConges = new DefaultScheduleModel();
        }



    }

    public void updateSchedule(){

        visualiseurConges.addEvent(new DefaultScheduleEvent("test" , new Date(), new Date() ));



    }

    public void setVisualiseurConges(DefaultScheduleModel visualiseurConges) {
        this.visualiseurConges = visualiseurConges;
    }

    public DefaultScheduleModel getVisualiseurConges() {



        return visualiseurConges;
    }

    public void setSessionBean(SessionMBean sessionBean) {
        this.sessionBean = sessionBean;
    }

    public SessionMBean getSessionBean() {
        return sessionBean;
    }



}

here is the full-stack trace

GRAVE: java.io.NotSerializableException: fr.novae.conseil.gestion.ejb.security.__EJB31_Generated__AuthenticationBean__Intf____Bean__
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at java.util.HashMap.writeObject(HashMap.java:1001)
    at sun.reflect.GeneratedMethodAccessor592.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at java.util.HashMap.writeObject(HashMap.java:1001)
    at sun.reflect.GeneratedMethodAccessor592.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at com.sun.faces.renderkit.ClientSideStateHelper.doWriteState(ClientSideStateHelper.java:293)
    at com.sun.faces.renderkit.ClientSideStateHelper.writeState(ClientSideStateHelper.java:167)
    at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:123)
    at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:155)
    at org.primefaces.application.PrimeFacesPhaseListener.writeState(PrimeFacesPhaseListener.java:174)
    at org.primefaces.application.PrimeFacesPhaseListener.handleAjaxRequest(PrimeFacesPhaseListener.java:111)
    at org.primefaces.application.PrimeFacesPhaseListener.beforePhase(PrimeFacesPhaseListener.java:74)
    at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:619)

thanks in advance

+2  A: 

@ViewScoped beans are stored in the JSF view state. If you explicitly have set the view state saving to client instead of (default) server (to save server side memory? it has however a network bandwidth cost), then any objects which are stored in the view state needs to implement Serializable.

The NotSerializableException is usually self-explaining since it mentions the full qualified name of the class which needs to be serialized as well, but can't be since it doesn't implement Serializable.

However, in this particular case the name seems to indicate an autogenerated class, most likely autogenerated by the EJB container and thus completely out of your control.

I've never seen this problem before and Google also doesn't seem to give much about this problem. Based on the stacktrace you're using Glassfish v3, so I'd suggest to post an issue about that. In the meanwhile your best bet is probably to set the JSF view state saving to the server side instead or to set the @EJB property to transient so that it doesn't get serialized. A bit decent container would reinject it after deserialization.

BalusC
Hi, thank you for your answer, actually the "view-state saving" was set to "CLIENT" I didn't realise that since the web.xml file was automatically generated by the IDE. However I thought "client state saving" was the way to go, but from what I can see if i want to use @ViewScoped managed-beans I need to either change it to "server state saving" or make all my EJB and ManagedBeans implement serializable which I think is a bit complicated....
ufasoli
There you have the IDE for. To autogenerate code. You only have to understand what the IDE does and how to use it properly :) I'd personally just get rid of the client side state saving. Server memory is cheaper than network bandwidth and the user experience will be more improved when the HTTP data transfer goes faster.
BalusC
yeah! thank you VERY VERY much, you and your articles have saved me a lot of time once again!
ufasoli
You're welcome :)
BalusC