问题
I am developing a web application using JSF on Netbeans 7.0. I have created 2 pages: one for entering persons name and other to display that name. I am using a java bean with get and set methods.
I get an error when I submit my form on first page the code.
This is my first page index.xhtml to accept name:
<h:form>
Enter your Name : <h:inputText value="#{demoBean.name}" required="true"/>
<br/> <h:commandButton value="Submit" action="welcome.xhtml"/>
</h:form>
This is the other page welcome.xhtml to display the name:
<h:body>
Hello #{demoBean.name}
</h:body>
This is the managed bean demoBean.java:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean()
@SessionScoped
public class demoBean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
This is the error which I got when I submit the fist page:
/index.xhtml @10,86 value="#{demoBean.name}": Target Unreachable, identifier 'demoBean'
resolved to null
回答1:
The JSP framework expects your bean class name to conform to the Java naming conventions, i.e. be "CamelCased" (e.g. DemoBean), in which case it will assume the bean will be referenced in the JSP by the default name formed by converting the first character of the bean name to lower case (demoBean).
As you have deviated from the framework's expectations, you need to indicate the name by which you refer to your bean in the JSPs, either by specifying it in the @ManagedBean annotation or in the optional faces-config.xml file.
回答2:
I had a similar issue. I added an extra annotation. { @Named("demobean") }
回答3:
Another thing to check is to make sure you have all of the required jars in your path(or use maven:) ). I started getting this issue in Glassfish with all of my beans properly set because I changed the directory that stores my Primefaces3.5 jar.
来源:https://stackoverflow.com/questions/9062699/target-unreachable-identifier-demobean-resolved-to-null