0
votes

I am trying to run a simple JSF 2.0 project using prime faces 3.5 on Apache Tomcat 7.0. I used annotations for Managed Bean.

I'm getting this error on submit of index.xhtml

javax.el.PropertyNotFoundException: /index.xhtml @16,60 value="#{homeBean.firstname}": Target Unreachable, identifier 'homeBean' resolved to null
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
org.primefaces.renderkit.InputRenderer.findImplicitConverter(InputRenderer.java:170)
org.primefaces.renderkit.InputRenderer.findConverter(InputRenderer.java:190)
org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:196)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
javax.faces.component.UIInput.validate(UIInput.java:953)
javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
javax.faces.component.UIInput.processValidators(UIInput.java:693)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIForm.processValidators(UIForm.java:240)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)

Below is the code which includes Managed Bean, welcome page, deployment descriptor, faces-config:

package main.com.java;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class HomeBean implements Serializable
{
    private static final long serialVersionUID = 1L;
    private String firstname;

    public String getFirstname()
    {
        return firstname;
    }

    public void setFirstname(String firstname)
    {
        this.firstname = firstname;
    }

}

index.xhtml :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Home Page</title>
</head>
<body>
    <f:view>
        <h:form id="form">
            <h:panelGrid columns="4" cellpadding="5">
                <h:outputLabel for="name" value="Name:" style="font-weight:bold" />
                <p:inputText id="name" value="#{homeBean.firstname}" />
                <p:commandButton value="Submit" update="display" />
                <h:outputText value="#{homeBean.firstname}" id="display" />
            </h:panelGrid>
        </h:form>
    </f:view>
</body>
</html>

faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
</faces-config>

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"
    id="WebApp_ID" version="3.0">
    <display-name>JSFExample</display-name>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <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>
</web-app>
1

1 Answers

1
votes

I've created and tested a project with supplied configurations and can't reproduce your error. I suspect that you've not rebuilt/redeployed your project.

Moreover, you should use h:head and h:body in JSF 2. If you omit h:head, PrimeFaces wont be able to add required scripts for AJAX functions so your project can't work. So you should change your index.xhtml like this :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Home Page</title>
</h:head>
<h:body>
    <f:view>
        <h:form id="form">
            <h:panelGrid columns="4" cellpadding="5">
                <h:outputLabel for="name" value="Name:" style="font-weight:bold" />
                <p:inputText id="name" value="#{homeBean.firstname}" />
                <p:commandButton value="Submit" update="display" />
                <h:outputText value="#{homeBean.firstname}" id="display" />
            </h:panelGrid>
        </h:form>
    </f:view>
</h:body>
</html>