jsf - View scope: java.io.NotSerializableException: javax.faces.component.html.HtmlInputText -


there error each time button calls action backing-bean. applies beans view scope , haven't found way fix without regression on other modules in code.

defaultfacele e   exiting serializeview - not serialize state: javax.faces.component.html.htmlinputtext  java.io.notserializableexception: javax.faces.component.html.htmlinputtext     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1184) 

or also:

com.ibm.ws.webcontainer.servlet.servletwrapper service srve0014e: uncaught service() exception  root cause faces servlet: servletexception: /jspfiles/jsf/deployments/editqueue.faces no saved view state found view identifier /jspfiles/jsf/deployments/editqueue.faces      @ javax.faces.webapp.facesservlet.service(facesservlet.java:205)  caused by: javax.faces.application.viewexpiredexception: /jspfiles/jsf/deployments/editqueue.faces no saved view state found view identifier:  /jspfiles/jsf/deployments/editqueue.faces     @ org.apache.myfaces.lifecycle.restoreviewexecutor.execute (restoreviewexecutor.java:128) 

faces-config.xml

<managed-bean>   <managed-bean-name>pc_editqueue</managed-bean-name>   <managed-bean-class>pagecode.jspfiles.jsf.deployments.editqueue</managed-bean-class>   <managed-bean-scope>view</managed-bean-scope>   <managed-property>     <property-name>queuedeploymentbean</property-name>     <value>#{queuedeploymentbean}</value>   </managed-property> </managed-bean> 

web.xml

<context-param>   <param-name>javax.faces.state_saving_method</param-name>   <param-value>server</param-value> </context-param> <context-param>   <param-name>org.apache.myfaces.serialize_state_in_session</param-name>   <param-value>true</param-value> </context-param> 

bean:

@managedbean @viewscoped public class editqueue extends pagecodebase implements serializable {   private static final long serialversionuid = -1l;   public string dobuttonaddaction() {     // calls manager (long)     facesutil.setviewmapvalue("queuedeploymentbean", queuedeploymentbean);     return ""; } 

i read suggestion set serialize_state_in_session false , indeed solution works view scope bean. fix comes @ high cost: many existing modules in application don't work anymore cannot use fix there. of regression observed are:

// returns null must changed facesutil.getsessionmapvalue("userid");  getsessionscope().get("userid");`  // returns null must changed facesutil.getviewmapvalue("linkerbean"); linkerbean = (linker) getmanagedbean("linkerbean");`  // npe must changed facescontext.getcurrentinstance().addmessage(...) getfacescontext().addmessage(...)` 

so questions are:

  1. why notserializableexception though bean implements serializable ?
  2. is there way apply serialize_state_in_session param on subset of beans or not ?
  3. is there solution have view scope bean work (without having change them request scope or else) ?

    websphere 8.0.0.3, java 1.6.0, jsf 2.0, richfaces 4.2.3.final

why notserializableexception though bean implements serializable ?

not bean needs serializable, of properties (and nested properties etc) must serializable. name of offending non-serializable class can found in exception message:

java.io.notserializableexception: javax.faces.component.html.htmlinputtext     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1184) 

this suggests you're binding <h:inputtext> component bean below:

<h:inputtext binding="#{bean.fooinput}" ...> 
private uicomponent fooinput; 

this indeed illegal when bean not in request scope. uicomponent instances request scoped , may not shared across multiple requests. moreover, uicomponent instances not serializable. state is, jsf worry itself.

you must remove fooinput property , need different solution problem incorrectly thought binding component view scoped bean right solution.

  • if intend access elsewhere in view, e.g. #{bean.fooinput.value}, bind facelet scope without need bean property:

    <h:inputtext binding="#{fooinput}" ...> 

    it'll available elsewhere in same view via #{fooinput.xxx}.

    <h:inputtext ... required="#{empty fooinput.value}" /> 

  • if intend set component attribute programmatically inside bean, e.g. fooinput.setstyleclass("someclass"), or fooinput.setdisabled(true), should binding specific attribute in view instead of whole component:

    <h:inputtext ... styleclass="#{bean.styleclass}" /> ... <h:inputtext ... disabled="#{bean.disabled}" /> 

  • if absolutely positive need hand of whole uicomponent instance in bean whatever reason, manually grab in method local scope instead of binding it:

    public void somemethod() {     uiviewroot view = facescontext.getcurrentinstance().getviewroot();     uicomponent fooinput = view.findcomponent("formid:fooinputid");     // ... } 

    but better ask question or search answer how solve concrete problem differently without need grab whole component in backing bean.

see also:


as viewexpiredexception, has different grounds further elaborated in javax.faces.application.viewexpiredexception: view not restored.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -