您好我有两个XHTML页面: 1-login.jsf 2-menu.jsf 我试图通过点击一个按钮从第1页到第2页,但它不起作用。这是我的代码: login.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的代码:
package com.fst.bibliotheque.beans;
import javax.faces.application.FacesMessage; import 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>
在执行applcation后我在我的控制台中有这个: janv。 09,2014 11:00:41 PM com.sun.faces.renderkit.html_basic.MessageRenderer encodeEnd 警告:'for'属性不能为null 谁知道问题出在哪里?
答案 0 :(得分:0)
有一个首都&#39; L&#39;在
<from-action>#{LoginBean.authentification()}</from-action>
它应该是小写的:
<from-action>#{loginBean.authentification()}</from-action>