JSF页面inputtext不会在bean中设置属性

问题描述:

我的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

使它像

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