You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by julius <co...@yahoo.com> on 2013/02/17 23:09:55 UTC

target unreachable / saved view state could not be found


hi,


i have used a simple eclipse jsf tutorial as a starting point and added a ajax part to it.
this is my first ajax project with eclipse/myfaces and im a bit confused
what is needed for a very basic project, the tutorials on the net all 
seem to be outdated, incomplete or simply wrong.

running the project for the first time in eclipse i get this:

javax.servlet.ServletException: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'LoginBean' resolved to null javax.faces.webapp.FacesServlet.service(FacesServlet.java:229) 


stopping the server from eclipse and running the project again i get:
javax.servlet.ServletException: /login.xhtmlNo saved view state could be found for the view identifier: /login.xhtml
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)

ive started with this code:
http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jst.jsf.doc.user%2Fhtml%2Fgettingstarted%2Ftutorial%2FJSFTools_tutorial_JSF20.html

it worked, logging in with a random username/password did bring me to the next page and displayed the username as expected.
navifation is from login.xhtml to welcome.xhtml.


now i added the ajax code on the welcome.xhtml page, for now i just want to get something updated. in this case the number of chars that is entered.


for the first error, this is my LoginBean.java:
/**
 * LoginBean.java
 * 
 */

package com.tutorial;
import javax.faces.event.AjaxBehaviorEvent;

public class LoginBean
{
    private String name;
    private String password;
    public int eventCount = 0;


    public String getName ()
    {
        return name;
    }


    public void setName (final String name)
    {
        this.name = name;
    }


    public String getPassword ()
    {
        return password;
    }


    public void setPassword (final String password)
    {
        this.password = password;
    }

    public void update (AjaxBehaviorEvent event)
    {
        eventCount++;
    }
}


as you can see, nothing fancy. update() is the listener method for the ajax update.



login.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

<html xmlns="http://www.w3.org/1999/xhtml";
    xmlns:ui="http://java.sun.com/jsf/facelets";
    xmlns:h="http://java.sun.com/jsf/html";
    xmlns:f="http://java.sun.com/jsf/core";>

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">
    <ui:define name="content">
        <h:form>
            <h:panelGrid columns="2">
                <h:outputText value="Name"></h:outputText>
                <h:inputText value="#{loginBean.name}"></h:inputText>
                <h:outputText value="Password"></h:outputText>
                <h:inputSecret value="#{loginBean.password}"></h:inputSecret>
            </h:panelGrid>
            <h:commandButton value="Login" action="login"></h:commandButton>
        </h:form>

    </ui:define>
</ui:composition>
</html>


welcome.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

<html xmlns="http://www.w3.org/1999/xhtml";
    xmlns:ui="http://java.sun.com/jsf/facelets";
    xmlns:h="http://java.sun.com/jsf/html";
    xmlns:f="http://java.sun.com/jsf/core";>

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">
    <ui:define name="content">
        <h:outputLabel value="Welcome #{LoginBean.name}" for="outputText"/>
        <h:form>
            <h:inputText id="myinput" value="#{LoginBean.name}">
                <f:ajax render="outtext" event="keyup" listener="#{LoginBean.update}"/>
            </h:inputText>

            <h:outputText id="outtext" value="#{loginBean.eventCount}"/>
        </h:form>
    </ui:define>
</ui:composition>
</html>


for="outputText": outputText is non existing, someone from a german java forum told me that it is needed even if it doesnt link anywhere.



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_3_0.xsd"; version="3.0">
  <display-name>webprojecttest</display-name>
  <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>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
  </context-param>
  <context-param>
    <description>
    This parameter tells MyFaces if javascript code should be allowed in
    the rendered HTML output.
    If javascript is allowed, command_link anchors will have javascript code
    that submits the corresponding form.
    If javascript is not allowed, the state saving info and nested parameters
    will be added as url parameters.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>
    If true, rendered HTML code will be formatted, so that it is 'human-readable'
    i.e. additional line separators and whitespace will be written, that do not
    influence the HTML code.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>
    If true, a javascript function will be rendered that is able to restore the
    former vertical scroll on every request. Convenient feature if you have pages
    with long lists and you do not want the browser page to always jump to the top
    if you trigger a link or button action that stays on the same page.
    Default is 'false'
</description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
        <param-name>org.apache.myfaces.USE_ENCRYPTION</param-name>
        <param-value>false</param-value>
     </context-param>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>
</web-app>


ive read:
http://wiki.apache.org/myfaces/Secure_Your_Application
and disabled encryption for testing, but the error is still there.
any idea what might be wrong?

Re: target unreachable / saved view state could not be found

Posted by vma <vm...@itc.tambov.gov.ru>.
Hi, julius

You have 'LoginBean' instead of 'loginBean' (first letter capitalized) in your 
welcome.xhtml page.

Vladimir M.

>   hi,
>   
>   
>   i have used a simple eclipse jsf tutorial as a starting point and added a
>   ajax part to it. this is my first ajax project with eclipse/myfaces and
>   im a bit confused what is needed for a very basic project, the tutorials
>   on the net all seem to be outdated, incomplete or simply wrong.
>   
>   running the project for the first time in eclipse i get this:
>   
>   javax.servlet.ServletException: javax.el.PropertyNotFoundException: Target
>   Unreachable, identifier 'LoginBean' resolved to null
>   javax.faces.webapp.FacesServlet.service(FacesServlet.java:229)
>   
>   
>   stopping the server from eclipse and running the project again i get:
>   javax.servlet.ServletException: /login.xhtmlNo saved view state could be
>   found for the view identifier: /login.xhtml
>   javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
>   
>   ive started with this code:
>   http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jst.jsf.doc.
>   user%2Fhtml%2Fgettingstarted%2Ftutorial%2FJSFTools_tutorial_JSF20.html
>   
>   it worked, logging in with a random username/password did bring me to the
>   next page and displayed the username as expected. navifation is from
>   login.xhtml to welcome.xhtml.
>   
>   
>   now i added the ajax code on the welcome.xhtml page, for now i just want
>   to get something updated. in this case the number of chars that is
>   entered.
>   
>   
>   for the first error, this is my LoginBean.java:
>   /**
>    * LoginBean.java
>    *
>    */
>   
>   package com.tutorial;
>   import javax.faces.event.AjaxBehaviorEvent;
>   
>   public class LoginBean
>   {
>       private String name;
>       private String password;
>       public int eventCount = 0;
>   
>   
>       public String getName ()
>       {
>           return name;
>       }
>   
>   
>       public void setName (final String name)
>       {
>           this.name = name;
>       }
>   
>   
>       public String getPassword ()
>       {
>           return password;
>       }
>   
>   
>       public void setPassword (final String password)
>       {
>           this.password = password;
>       }
>   
>       public void update (AjaxBehaviorEvent event)
>       {
>           eventCount++;
>       }
>   }
>   
>   
>   as you can see, nothing fancy. update() is the listener method for the
>   ajax update.
>   
>   
>   
>   login.xhtml
>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
>   
>   <html xmlns="http://www.w3.org/1999/xhtml";
>       xmlns:ui="http://java.sun.com/jsf/facelets";
>       xmlns:h="http://java.sun.com/jsf/html";
>       xmlns:f="http://java.sun.com/jsf/core";>
>   
>   <ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">
>       <ui:define name="content">
>           <h:form>
>               <h:panelGrid columns="2">
>                   <h:outputText value="Name"></h:outputText>
>                   <h:inputText value="#{loginBean.name}"></h:inputText>
>                   <h:outputText value="Password"></h:outputText>
>                   <h:inputSecret
>   value="#{loginBean.password}"></h:inputSecret> </h:panelGrid>
>               <h:commandButton value="Login"
>   action="login"></h:commandButton> </h:form>
>   
>       </ui:define>
>   </ui:composition>
>   </html>
>   
>   
>   welcome.xhtml
>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
>   
>   <html xmlns="http://www.w3.org/1999/xhtml";
>       xmlns:ui="http://java.sun.com/jsf/facelets";
>       xmlns:h="http://java.sun.com/jsf/html";
>       xmlns:f="http://java.sun.com/jsf/core";>
>   
>   <ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">
>       <ui:define name="content">
>           <h:outputLabel value="Welcome #{LoginBean.name}"
>   for="outputText"/> <h:form>
>               <h:inputText id="myinput" value="#{LoginBean.name}">
>                   <f:ajax render="outtext" event="keyup"
>   listener="#{LoginBean.update}"/> </h:inputText>
>   
>               <h:outputText id="outtext" value="#{loginBean.eventCount}"/>
>           </h:form>
>       </ui:define>
>   </ui:composition>
>   </html>
>   
>   
>   for="outputText": outputText is non existing, someone from a german java
>   forum told me that it is needed even if it doesnt link anywhere.
>   
>   
>   
>   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_3_0.xsd"; version="3.0">
>     <display-name>webprojecttest</display-name>
>     <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>
>     <context-param>
>      
>   <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
>   <param-value>resources.application</param-value>
>     </context-param>
>     <context-param>
>       <description>State saving method: 'client' or 'server' (=default). See
>   JSF Specification 2.5.2</description>
>   <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
>       <param-value>server</param-value>
>     </context-param>
>     <context-param>
>       <description>
>       This parameter tells MyFaces if javascript code should be allowed in
>       the rendered HTML output.
>       If javascript is allowed, command_link anchors will have javascript
>   code that submits the corresponding form.
>       If javascript is not allowed, the state saving info and nested
>   parameters will be added as url parameters.
>       Default is 'true'</description>
>       <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
>       <param-value>true</param-value>
>     </context-param>
>     <context-param>
>       <description>
>       If true, rendered HTML code will be formatted, so that it is
>   'human-readable' i.e. additional line separators and whitespace will be
>   written, that do not influence the HTML code.
>       Default is 'true'</description>
>       <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
>       <param-value>true</param-value>
>     </context-param>
>     <context-param>
>       <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
>       <param-value>false</param-value>
>     </context-param>
>     <context-param>
>       <description>
>       If true, a javascript function will be rendered that is able to
>   restore the former vertical scroll on every request. Convenient feature
>   if you have pages with long lists and you do not want the browser page to
>   always jump to the top if you trigger a link or button action that stays
>   on the same page. Default is 'false'
>   </description>
>       <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
>       <param-value>true</param-value>
>     </context-param>
>     <context-param>
>           <param-name>org.apache.myfaces.USE_ENCRYPTION</param-name>
>           <param-value>false</param-value>
>        </context-param>
>     <listener>
>      
>   <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</
>   listener-class> </listener>
>   </web-app>
>   
>   
>   ive read:
>   http://wiki.apache.org/myfaces/Secure_Your_Application
>   and disabled encryption for testing, but the error is still there.
>   any idea what might be wrong?