2016-06-01 3 views
-1

Je suis nouveau à jsf et je reçois une erreur d'analyse lors de l'exécution d'un formulaire simple. L'erreur dit "/enternameform.xhtml @ 17,59 value =" # {register.firstName} ": Target Inaccessible, identifiant 'registre' résolu à null"/enternameform.xhtml @ 17,59 value = "# {register.firstName}": Cible inaccessible, identifiant 'register' résolu à null

Mon code est ci-dessous

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> 

S'il vous plaît laissez-moi savoir ce que je peux faire mal ici.

Répondre

0

Il a été corrigé après le redémarrage du serveur n quelques modifications