2014-01-09 35 views
-1

您好,我有兩個XHTML頁面: 1 login.jsf 2 menu.jsf 我嘗試從第1頁去點擊一個按鈕,第2頁,但它不work.Here是我的代碼: login.jsfH:沒有的commandButton重定向到其他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;

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> 

我有這個在我的控制檯execuring的applcation後: janv。 09,2014 11:00:41 PM com.sun.faces.renderkit.html_basic.MessageRenderer encodeEnd 警告:'for'屬性不能爲空 任何人都知道問題出在哪裏?

回答

0

有一個在

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

一資「L」應該是小寫:

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

THX的答覆,但它並沒有解決problem.In其實我管理bean的名字是大寫「L」的LoginBean。 – user3179505

+0

是否調用了'authentification()'?因爲如果bean確實被命名爲LoginBean,那麼''中的操作是錯誤的或者這裏有一個錯字。 –

+0

解決了問題thx :) – user3179505

相關問題