2015-04-21 79 views
-1

我想跟隨一個非常基本的JSF教程,但我得到一個空指針在我的第二頁(test.xhtml),如果我嘗試讀取用戶名,但找不到在這裏我做錯了什麼。JSF - Managed Bean = null重定向後

這是我的豆:

import java.io.Serializable; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 

@ManagedBean 
@SessionScoped 
public class User implements Serializable { 

    private static final long serialVersionUID = 1L; 

    private String name; 

    public String getName() { 
     return name; 
    } 

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

} 

這是我出發的facelet:

<!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:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html"> 

<h:head></h:head> 
<body> 
    <h:form> 
     <h:inputText value="#{user.name}" /> 
     <h:commandLink action="test" value="go" /> 
    </h:form> 
</body> 
</html> 

而且我想在此的facelet打印名稱:

<!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:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html"> 

<h:head></h:head> 
<body> 
    <h:form> 
     <h:outputText value="#{user.name}" /> 
    </h:form> 
</body> 
</html> 

請告訴我錯誤這裏?

編輯:堆棧跟蹤:

00:09:04,468 ERROR [io.undertow.request] (default task-8) UT005023: Exception handling request to /TestJSF/index.xhtml;jsessionid=WmQDd1vj88TJk7m3GC8DuHSo.xxx: javax.servlet.ServletException: /index.xhtml @10,39 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) 
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) 
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) 
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) 
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) 
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) 
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) 
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) 
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) 
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) 
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:278) 
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:255) 
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80) 
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174) 
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) 
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:744) 
Caused by: javax.el.PropertyNotFoundException: /index.xhtml @10,39 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null 
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) 
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) 
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1045) 
    at javax.faces.component.UIInput.validate(UIInput.java:975) 
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1248) 
    at javax.faces.component.UIInput.processValidators(UIInput.java:712) 
    at javax.faces.component.UIForm.processValidators(UIForm.java:253) 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1260) 
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195) 
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) 
    ... 27 more 
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'user' resolved to null 
    at com.sun.el.parser.AstValue.getTarget(AstValue.java:174) 
    at com.sun.el.parser.AstValue.getType(AstValue.java:86) 
    at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201) 
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93) 
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93) 
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98) 
    ... 39 more 

編輯2:在faces-config.xml只是看起來像:

<?xml version="1.0" encoding="UTF-8"?> 
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"> 
</faces-config> 

的web.xml文件:

HTTP ://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd「> 面臨的Servlet javax.faces.webapp.FacesServlet 面孔的Servlet * .xhtml

<!-- Date Converter use system time zone instead of UTC --> 
    <context-param> 
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name> 
    <param-value>true</param-value> 
    </context-param> 

    <!-- Do not send XML comments to the client --> 
    <context-param> 
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> 
    <param-value>true</param-value> 
    </context-param> 

    <!-- Process zero-length input strings as null values --> 
    <context-param> 
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name> 
    <param-value>true</param-value> 
    </context-param> 

    <!-- Use development mode --> 
    <context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Development</param-value> 
    </context-param> 
    <context-param> 
    <param-name>facelets.DEVELOPMENT</param-name> 
    <param-value>true</param-value> 
    </context-param> 

    <!-- Welcome page --> 
    <welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
    </welcome-file-list> 
</web-app> 
+1

也許使用''。 – DavidS

+3

發佈空指針的堆棧跟蹤。 –

+0

你可以添加你的「faces-config.xml」嗎? –

回答

0

它接縫,問題是,豆是在沒有包(或默認包)。將其移至實際包裝可解決問題。