【问题标题】:h:commandButton not redirecting to other jsf pageh:commandButton 不重定向到其他 jsf 页面
【发布时间】:2014-01-09 22:12:02
【问题描述】:

您好,我有两个 XHTML 页面: 1-login.jsf 2-菜单.jsf 我试图通过单击一个按钮从第 1 页转到第 2 页,但它不起作用。这是我的代码: 登录.jsf

<!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://java.sun.com/jsf/html">

<head>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
</head>

<h:body>
<h:form id="LoginForm">
<h:panelGrid  style= "width: 467px; height: 88px">

<h:outputLabel value="Login"/>
<h:inputText value="#{loginBean.login}" id="loginID" />
<h:message for="loginID" tooltip="true" showDetail="true" showSummary="true" style="COLOR: #ff0000;"/>

<h:outputLabel value="Mot de Passe"/>
<h:inputSecret value="#{loginBean.password}" id="pwdID" />
<h:message for="pwdID" tooltip="true" showDetail="true" showSummary="true" style="COLOR:    #ff0000;"/>
<h:message />
</h:panelGrid>

<h:commandButton id="validerID" value="Valider" action="#{loginBean.authentification}"       type="submit"/>
<h:commandButton  id="resetID" value="Reset" type="reset"/>
</h:form>
</h:body>
</html>

这里是 ManagedBean 的代码:

包 com.fst.bibliotheque.beans;

导入 javax.faces.application.FacesMessage; 导入 javax.faces.context.FacesContext;

公共类 LoginBean {

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 authentification(){

    FacesContext fc=FacesContext.getCurrentInstance();
    if("admin".equals(this.login) && "admin".equals(password)){
        return "success";
    }else{
        if(!"admin".equals(this.login)){
            fc.addMessage("LoginForm:loginID",new    FacesMessage(FacesMessage.SEVERITY_INFO,"Validation Login","Login "+this.login+" inexistant!!"));
        }
        if(!"admin".equals(this.password)){
            fc.addMessage("LoginForm:pwdID",new FacesMessage(FacesMessage.SEVERITY_INFO, "Validation Pwd","Vérifier votre mot de passe!!"));
        }
        return "echec";
    }

}

}

最后是 faces-config.xml 中的导航规则

     <navigation-rule>
    <display-name>pages/login.xhtml</display-name>
    <from-view-id>/pages/login.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{LoginBean.authentification()}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/pages/menu.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

执行应用程序后,我的控制台中有这个: 一月。 2014 年 9 月 9 日晚上 11:00:41 com.sun.faces.renderkit.html_basic.MessageRenderer encodeEnd 警告:“for”属性不能为空 有谁知道问题出在哪里?

【问题讨论】:

    标签: java jsf jsf-2 primefaces commandbutton


    【解决方案1】:

    有一个大写的“L”

    <from-action>#{LoginBean.authentification()}</from-action>
    

    应该是小写的:

    <from-action>#{loginBean.authentification()}</from-action>
    

    【讨论】:

    • 感谢回复,但并没有解决问题。事实上,我的托管 bean 的名称是 LoginBean,大写“L”。
    • authentification() 真的被调用了吗?因为如果这个bean确实被命名为LoginBean,那么&lt;h:commandButton&gt;中的动作是错误的或者这里有错别字。
    猜你喜欢
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2018-07-10
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多