/enternameform.xhtml @ 17,59 value ="#{register.firstName}":目标无法访问,标识符'注册'解析为null

时间:2016-06-01 03:32:17

标签: jsf el propertynotfoundexception

我是jsf的新手,在运行简单表单时遇到解析错误。该错误表示" /enternameform.xhtml @ 17,59 value ="#{register.firstName}":目标无法访问,标识符'注册'解决为null"

我的代码在

下面

enternameform.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:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>registration form</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<div align="center">
<h1 class="title">Enter Name and Register</h1>
<br/>
<fieldset>
<legend>Please Enter Name here</legend>
<h:form>
  <!-- Your form elements here -->
  First Name: <h:inputText value="#{register.firstName}"/> <br/>
  Last Name: <h:inputText value="#{register.lastName}"/><br/>
  <h:commandButton value="go ahead" action="#{register.fullName}"/>
</h:form>
</fieldset>
</div>
</h:body></html>

Register.java

package registrationform;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Register {

    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String fullName (){
        if(isMissing(firstName)|| isMissing(lastName)){
            return("missing");
        }else{
            return("registrationsuccess");
        }
    }

    private boolean isMissing(String name){
        return (name.trim().isEmpty());
        }
    }

missing.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:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>missing</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">Please enter both First and Last Name to Register</h1>
<a href="enternameform.xhtml">Try again here</a>
</h:body></html>

registrationsuccess.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:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>registrationsuccess</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">You have completed registration</h1>
First Name: #{register.firstName} <br/>
Last Name:#{register.lastName}
</h:body></html>

的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" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         version="3.0">
  <!-- The bare minimum needed for JSF 2.2 is a servlet 2.5 or later
       declaration (this uses 3.0) and the mapping for the FacesServlet.
       Setting PROJECT_STAGE to Development is highly recommended
       during initial development so that you get more helpful
       error messages. Whether you want server-side state saving
       (default) or client-side is a more complicated question:
       client-side uses more bandwidth but fewer server resources.
       Client-side also helps to avoid the dreaded view expired exceptions.

       From JSF 2 and PrimeFaces tutorial 
       at http://www.coreservlets.com/JSF-Tutorial/jsf2/
  -->
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <!-- If you go to http://host/project/ (with no file name), it will
       try index.jsf first, welcome.jsf next, and so forth.
   -->
  <welcome-file-list>
    <welcome-file>enternameform.jsf</welcome-file>
    <welcome-file>welcome.jsf</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

请让我知道我在这里做错了什么。

1 个答案:

答案 0 :(得分:0)

重新启动服务器n一些编辑后已修复