简体   繁体   English

JSF页面inputtext未在bean中设置属性

[英]JSF Page inputtext doesn't set property in bean

My JSF login page doesn't set the property in my bean. 我的JSF登录页面未在bean中设置属性。 This is the part of my Login.xhtml: 这是我的Login.xhtml的一部分:

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

The 'gebruiker' and 'wachtwoord' should be set in the bean in the following code: 应该在Bean中通过以下代码设置'gebruiker'和'wachtwoord':

@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";
    }

} }

When I debug in Netbeans, the values 'gebruiker' and 'wachtwoord' are null. 当我在Netbeans中调试时,值'gebruiker'和'wachtwoord'为空。

Make it like 使它像

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

@ManagedBean
@SessionScoped
public class ControllerBean implements Serializable {

@ManagedBean will by default add name of the bean to controllerBean and also will register this POJO as ManagedBaen @ManagedBean默认情况下会将bean的名称添加到controllerBean ,并将此POJO注册为ManagedBaen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM