3 Replies Latest reply on Feb 7, 2007 4:11 AM by gonzalad

    NotSerializableException on JSF rendering (scope Page)

    gonzalad Apprentice

      Hello,

      I'm just beginning development with Seam.

      I'm trying to build a CRUD application based on the booking sample.

      I've a JSF page showing a list backed by an ActionList bean.

      When I use session scope for this bean, the page renders fine.

      When I use page scope for this bean, seam exception page shows with the following stack Trace.

      Has anyone experienced this error ?

      java.io.NotSerializableException: java.lang.ThreadLocal
      javax.faces.FacesException: java.io.NotSerializableException: java.lang.ThreadLocal
      at org.apache.myfaces.shared_impl.util.StateUtils.getAsByteArray(StateUtils.java:190)
      at org.apache.myfaces.shared_impl.util.StateUtils.construct(StateUtils.java:150)
      at org.apache.myfaces.renderkit.html.HtmlResponseStateManager.writeState(HtmlResponseStateManager.java:102)
      at org.apache.myfaces.application.jsp.JspStateManagerImpl.writeState(JspStateManagerImpl.java:430)
      at org.ajax4jsf.framework.ajax.AjaxStateManager.writeState(AjaxStateManager.java:91)
      at org.jboss.seam.jsf.SeamStateManager.writeState(SeamStateManager.java:66)
      at org.ajax4jsf.framework.ajax.AjaxStateManager.writeState(AjaxStateManager.java:91)
      at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:599)
      at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:101)
      at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:222)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:907)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
      at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:46)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
      at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:32)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
      at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:75)
      at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:213)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:701)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:646)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:475)
      at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
      at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:92)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
      at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:93)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:274)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
      at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:741)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)
      Caused by: java.io.NotSerializableException: java.lang.ThreadLocal
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1108)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1462)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1434)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1377)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1106)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:324)
      at java.util.ArrayList.writeObject(ArrayList.java:595)
      at sun.reflect.GeneratedMethodAccessor3547.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:615)
      at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:972)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1426)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1377)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1106)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1462)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1434)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1377)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1106)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:324)
      at java.util.HashMap.writeObject(HashMap.java:1040)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:615)
      at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:972)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1426)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1377)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1106)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1102)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1102)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1102)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1102)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:324)
      at org.apache.myfaces.shared_impl.util.StateUtils.getAsByteArray(StateUtils.java:180)
      ... 46 more



      Here is the bean code :

      package org.pag.seam.example.employe;
      
      import java.io.Serializable;
      import java.util.List;
      
      import org.hibernate.Session;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.example.hibernate.Hotel;
      import org.jboss.seam.log.Log;
      
      
      @Name("employeListAction")
      @Scope(ScopeType.PAGE)
      public class EmployeListAction implements Serializable {
       private static final long serialVersionUID = -7659479980987467214L;
      
       @DataModel
       private transient List<Employe> employeList;
      
       @In
       private transient Session bookingDatabase;
       private int pageSize = 10;
       private int page = 0;
       private boolean nextPageAvailable = false;
      
       @Logger
       private transient Log log;
       private String searchString = null;
      
       public EmployeListAction () {
       System.out.println("EmployeManagerAction.new() : "+this);
       }
      
       public String getSearchString() {
       return searchString;
       }
      
       public void setSearchString(String aSearchString) {
       searchString = aSearchString;
       }
      
       public void find () {
       page = 0;
       queryEmployes ();
       }
      
       public int getPage() {
       return page;
       }
      
       public void setPage(int page) {
       this.page = page;
       }
      
       private void queryEmployes() {
      
       log.info ("queryEmploye - employeManager=#{employeManager}, employes=#{employes}, page=#{employeListAction.page}");
       String findPattern = searchString==null ? "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
       employeList = (List<Employe>) bookingDatabase.createQuery("select e from Employe e where lower(e.name) like :find")
       .setParameter("find", findPattern)
       .setMaxResults(pageSize)
       .setFirstResult( page * pageSize )
       .list();
       }
      
       public void nextPage()
       {
       page++;
       queryEmployes();
       }
      
       public boolean isNextPageAvailable()
       {
       return employeList!=null && employeList.size()==pageSize;
       }
      
       public void previousPage()
       {
       page--;
       queryEmployes();
       }
      
       public boolean isPreviousPageAvailable()
       {
       return page>0;
       }
      
       public int getPageSize() {
       return pageSize;
       }
      
       public void setPageSize(int aPageSize) {
       pageSize = aPageSize;
       }
      }