簡體   English   中英

在JSF中導航

[英]Navigation in JSF

早上好! 我是新手。 我有一個簡單的JSF應用程序。 但它沒有按預期工作。 這是我的login.xhtml:

<h:body>
    <h:outputText value="Please enter your login and password"/>
    <h:form id="loginForm">
        <h:panelGrid columns="2">       
                <h:outputText value="User name"/>                   
                <h:inputText value="#{textBean.login}" required="true"/>
                <h:outputText value="Password"/>
                <h:inputSecret value="#{textBean.password}" required="true"/>
                <h:commandButton value="Submit" action="#{textBean.doLogin}"/>
        </h:panelGrid> 
    </h:form>
</h:body>

這是我的error.xhtml:

<h:body>
    <h:outputText value="You have entered incorrect data"/>
    <h:form id="errorForm">    
                <h:commandLink value="Back to login page" action="#{TextBean.backToLogin}"/>
    </h:form>
</h:body>

這是我的bean類TextBean.java:

公共類TextBean實現Serializable {

private static final long serialVersionUID = 1L;

private String login;

private String password;

public String getLogin() {
    return login;
}

public void setLogin(String login) {
    this.login = login;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String doLogin() {
    if ("admin".equals(login) && "mypass".equals(password)) {
        return "welcome";
    } else {
        return "error";
    }

}

public String backToLogin() {
        return "login";
}

}

為什么錯誤頁面不會返回登錄頁面? 當您點擊“返回登錄頁面”鏈接時,我得到了例外。 我究竟做錯了什么? 這是我的例外:

        The server encountered an internal error () that prevented it from fulfilling this request.
javax.servlet.ServletException: javax.el.PropertyNotFoundException: /error.xhtml @14,80 action="#{TextBean.doMyLogin}": Target Unreachable, identifier 'TextBean' resolved to null
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:521)
javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /error.xhtml @14,80 action="#{TextBean.doMyLogin}": Target Unreachable, identifier 'TextBean' resolved to null
    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:95)
    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    javax.faces.component.UICommand.broadcast(UICommand.java:315)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
javax.el.PropertyNotFoundException: /error.xhtml @14,80 action="#{TextBean.doMyLogin}": Target Unreachable, identifier 'TextBean' resolved to null
    com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)
        javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    javax.faces.component.UICommand.broadcast(UICommand.java:315)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)

親愛的朋友,請幫幫我! 任何幫助將不勝感激。

bean的名稱是textBean而不是TextBean 這就是為什么JSF無法解決它: identifier 'TextBean' resolved to null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM