2011-04-15 103 views
0

我的JSF登錄頁面沒有在我的bean中設置屬性。這是我Login.xhtml部分:JSF頁面inputtext不會在bean中設置屬性

<h:form> 
<h:outputLabel value="#{controllerBean.foutmelding}" id="foutmelding"></h:outputLabel><br /> 
<table width="50px" align="center"> 
    <tr> 
     <td align="left"> 
      <h:outputLabel for="gebruiker" value="Gebruikersnaam:"/> 
     </td> 
     <td> 
      <h:inputText id="gebruiker" required="true" value="#{controllerBean.gebruiker}"></h:inputText> 
     </td> 
    </tr> 
    <tr> 
     <td align="left"> 
      <h:outputLabel for="wachtwoord" value="Wachtwoord:"/> 
     </td> 
     <td> 
      <h:inputSecret id="wachtwoord" required="true" value="#{controllerBean.wachtwoord}"></h:inputSecret> 
     </td> 
    </tr> 
    <tr> 
     <td align="right" colspan="2"> 
      <h:commandButton value="Inloggen" styleClass="button" action="#{controllerBean.showLogin}"></h:commandButton> 
     </td> 
    </tr> 
</table> 
</h:form> 

的 'gebruiker' 和 'wachtwoord' 應該在bean下面的代碼來設置:

@Named(value="controllerBean") 
@SessionScoped 
public class ControllerBean implements Serializable { 

/** Datafields */ 
public String gebruiker; 
public String wachtwoord; 

public String getGebruiker() { 
    return gebruiker; 
} 

public void setGebruiker(String gebruiker) { 
    this.gebruiker = gebruiker; 
} 

public void setWachtwoord(String wachtwoord) { 
    this.wachtwoord = wachtwoord; 
} 

public String getWachtwoord() { 
    return wachtwoord; 
} 

public String showLogin() { 
    if (gebruiker != null && gebruiker.length() > 0 && wachtwoord != null && wachtwoord.length() > 0) { 
     Klant k = controller.getKlant(gebruiker); 
     if (k == null) { 
       foutmelding = "Gebruikersnaam is onjuist."; 
       return "Login.xhtml"; 
      } 
      if (!k.getWachtwoord().equals(wachtwoord)) { 
       foutmelding = "Wachtwoord is onjuist."; 
       return "Login.xhtml"; 
      } 
      ingelogdeKlant = k; 
      foutmelding = ""; 
      return "Home.xhtml"; 

     } else { 
      // Geen gebruikersnaam of wachtwoord ingevuld. 
      foutmelding = "Vul uw gebruikersnaam en wachtwoord in."; 
     } 
     return "Login.xhtml"; 
    } 

}

當我在NetBeans中進行調試時,值「gebruiker」和「wachtwoord」爲空。

+0

你有'H:messages'標記您的登錄頁面上? – wjans 2011-04-15 09:53:43

回答

1

使它像

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import java.io.Serializable; 

@ManagedBean 
@SessionScoped 
public class ControllerBean implements Serializable { 

@ManagedBean將默認的bean的名字添加到controllerBean也將註冊該POJO作爲ManagedBaen