java ee - JSF Expired ViewScope issue -


i using jsf2.2 & tomcat 6.0.35. have application, display & edit user details. sending ajax request processing on change of each input edit details & updating form.

when try change input after long idle time (after 30 mins), getting nullpointerexception managed bean instance variable. server has cleaned instantiations idle long time, client-browser doesn’t know ?

here code.

commontemplate.xhtml

<!doctype html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"     xmlns:f="http://java.sun.com/jsf/core"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:c="http://java.sun.com/jsp/jstl/core"     xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title> vsp </title> <meta http-equiv="expires" content="0"/> <meta http-equiv="pragma" content="no-cache"/> <meta http-equiv="cache-control" content="no-cache"/> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="vsp.css" type="text/css" /> <script type="text/javascript"> //<![cdata[ jquery("#designform :input[type='text']:enabled:not([readonly='readonly'])").live('change', function(){     var componentid = jquery(this).attr("id");     validateinputdata(componentid);     var validform = (jquery(".errormsg").length == 0) ? true : false;     if(validform){         jquery("#submitdesignform").click();     } });  </script> </h:head> <h:body>     <div id="header">         <ui:insert name="commonheader">             <ui:include src="header.xhtml" />         </ui:insert>     </div>     <div id="content">         <ui:insert name="commonbodycontent">             <h:form id="designform" prependid="false" autocomplete="off">                 common body content.             <h:commandlink id="submitdesignform" style="display:none;">                  <f:ajax execute="@form"                          render="@form"                         listener="#{designbean.processdetails}"/>             </h:commandlink>             </h:form>                    </ui:insert>     </div>     <div id="footer">         <ui:insert name="commonfooter">             <ui:include src="footer.xhtml" />         </ui:insert>     </div> </h:body> </html> 

showdetails.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"                 xmlns:f="http://java.sun.com/jsf/core"                 xmlns:h="http://java.sun.com/jsf/html"                 xmlns:ui="http://java.sun.com/jsf/facelets"                 template="commontemplate.xhtml">      <ui:define name="commonbodycontent">         <table>             <tr>                 <td>name</td>                 <td>#{designbean.person.name}</td>             </tr>             <tr>                 <td>age</td>                 <td>#{designbean.person.age}</td>             </tr>             <tr>                 <td>email</td>                 <td>#{designbean.person.email}</td>             </tr>             <tr>                 <td>nationality</td>                 <td>#{designbean.person.nation}</td>             </tr>             <tr>                 <td>date-of-birth</td>                 <td>#{designbean.person.dob}</td>             </tr>         .........;         ..........;         </table>     </ui:define>  </ui:composition>  editdetails.xhtml ------------------ <ui:composition xmlns="http://www.w3.org/1999/xhtml"                 xmlns:f="http://java.sun.com/jsf/core"                 xmlns:h="http://java.sun.com/jsf/html"                 xmlns:ui="http://java.sun.com/jsf/facelets"                 template="commontemplate.xhtml">      <ui:define name="commonbodycontent">         <table>             <tr>                 <td>name</td>                 <td><h:inputtext value="#{designbean.person.name}" /></td>             </tr>             <tr>                 <td>age</td>                 <td><h:inputtext value="#{designbean.person.age}" /></td>             </tr>             <tr>                 <td>email</td>                 <td><h:inputtext value="#{designbean.person.email}" disabled="true"/></td>             </tr>             <tr>                 <td>nationality</td>                 <td><h:inputtext value="#{designbean.person.nation}" /></td>             </tr>             <tr>                 <td>date-of-birth</td>                 <td><h:inputtext value="#{designbean.person.dob}" /></td>             </tr>         .........;         ..........;         </table>     </ui:define>  </ui:composition> 

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_2_5.xsd"     id="webapp_id" version="2.5">     <welcome-file-list>         <welcome-file>index.jsp</welcome-file>     </welcome-file-list>     <context-param>         <param-name>javax.faces.facelets_skip_comments</param-name>         <param-value>true</param-value>     </context-param>     <context-param>         <param-name>javax.faces.state_saving_method</param-name>         <param-value>client</param-value>     </context-param>     <context-param>         <param-name>javax.faces.default_suffix</param-name>         <param-value>.xhtml</param-value>     </context-param>     <context-param>         <param-name>javax.faces.separator_char</param-name>         <param-value>_</param-value>     </context-param>     <context-param>         <param-name>com.sun.faces.expressionfactory</param-name>         <param-value>org.jboss.el.expressionfactoryimpl</param-value>     </context-param>     <context-param>         <param-name>javax.faces.project_stage</param-name>         <param-value>development</param-value>     </context-param>     <context-param>         <param-name>javax.faces.datetimeconverter_default_timezone_is_system_timezone</param-name>         <param-value>true</param-value>     </context-param>     <context-param>         <param-name>com.sun.faces.disableunicodeescaping</param-name>         <param-value>true</param-value>     </context-param>     <filter>         <filter-name>characterencodingfilter</filter-name>         <filter-class>org.omnifaces.filter.characterencodingfilter</filter-class>     </filter>     <filter-mapping>         <filter-name>characterencodingfilter</filter-name>         <url-pattern>/*</url-pattern>     </filter-mapping>     <filter>         <filter-name>nocachefilter</filter-name>         <filter-class>org.omnifaces.filter.cachecontrolfilter</filter-class>     </filter>     <filter-mapping>         <filter-name>nocachefilter</filter-name>         <servlet-name>facesservlet</servlet-name>     </filter-mapping>     <filter>         <filter-name>facesexceptionfilter</filter-name>         <filter-class>org.omnifaces.filter.facesexceptionfilter</filter-class>     </filter>     <filter-mapping>         <filter-name>facesexceptionfilter</filter-name>         <servlet-name>facesservlet</servlet-name>     </filter-mapping>     <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>*.faces</url-pattern>     </servlet-mapping>     <error-page>         <exception-type>javax.faces.application.viewexpiredexception</exception-type>         <location>/viewexpired.faces</location>     </error-page>     <error-page>         <exception-type>java.sql.sqlexception</exception-type>         <location>/systemunavailable.faces</location>     </error-page>     <error-page>         <exception-type>java.lang.runtimeexception</exception-type>         <location>/error.faces</location>     </error-page>     <error-page>         <error-code>500</error-code>         <location>/error.faces</location>     </error-page>     <error-page>         <error-code>403</error-code>         <location>/invalidaccess.faces</location>     </error-page>     <error-page>         <error-code>404</error-code>         <location>/notfound.faces</location>     </error-page>     <security-constraint>         <display-name>restrict raw xhtml documents</display-name>         <web-resource-collection>             <web-resource-name>xhtml</web-resource-name>             <url-pattern>*.xhtml</url-pattern>         </web-resource-collection>         <auth-constraint />     </security-constraint> </web-app> 

designbean

@viewscoped @managedbean(name="designbean") public class designbean implements serializable{      @managedproperty(value = "#{userbean}")     private userbean userbean;      @managedproperty("#{userservice}")     private userservice userservice; // application scoped managed bean eager true.      private person person;      @postconstruct     public void initbean(){         system.out.println("designbean created!");         person = new person();         string useremail = userbean.getuseremail();         if(useremail!=null && !useremail.isempty()){             person = userservice.getuserdetails(useremail);         }     }      public void processdetails(){         person.setlastupdatetime(new date()); // getting npe here, person object null after long idle time.         userservice.updateuser(person);     }      public void setuserbean(userbean userbean) {         this.userbean = userbean;     }      public userbean getuserbean() {         return userbean;     }      public void setuserservice(userservice userservice) {         this.userservice = userservice;     }      public userservice getuserservice() {         return userservice;     }      public void setperson(person person){         this.person = person;     }      public person getperson(){         return person;     }  } 

person

public class person implements serializable {     private string name;     private integer age;     private string email;     private string nation;     private string dob;     private date lastupdatetime;      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public integer getage() {         return age;     }      public void setage(integer age) {         this.age = age;     }      public string getemail() {         return email;     }      public void setemail(string email) {         this.email = email;     }      public string getnation() {         return nation;     }      public void setnation(string nation) {         this.nation = nation;     }      public string getdob() {         return dob;     }      public void setdob(string dob) {         this.dob = dob;     }      public void setlastupdatetime(date lastupdatetime){         this.lastupdatetime = lastupdatetime;     }      public date getlastupdatetime(){         return lastupdatetime;     }  } 


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -