【问题标题】:Getting null values from jsf inputText in Manage bean从 Manage bean 中的 jsf inputText 获取空值
【发布时间】:2014-05-27 19:32:43
【问题描述】:

我在 jsf inputText 中遇到了奇怪的问题。在浏览器上,它在输入框中显示管理 bean 名称和变量名称(即 #{loginModel.userName})。以下是我的jsf页面代码

<body>
<f:view>
    <h:form>
        <h:outputLabel value="Username"></h:outputLabel>
        <h:inputText value="#{loginModel.userName}"></h:inputText>
        <h:outputLabel value="Password"></h:outputLabel>
        <h:inputSecret value="#{loginModel.password}"></h:inputSecret>
        <h:commandButton value="Submit" action="#{loginModel.process}" ></h:commandButton>
    </h:form>
</f:view>
</body>

我的管理 bean 代码是

public class LoginModel {

    private String userName;
    private String password;
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String process(){

        System.out.println("Logged in user id is "+this.getUserName()+" and password to access is "+this.getPassword());
        return "Submit";
    }

}

还有我的 faces-config.xml 文件

<managed-bean>
        <managed-bean-name>loginModel</managed-bean-name>
        <managed-bean-class>net.varun.dto.LoginModel</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

以下是我在浏览器上的输出,当我点击提交按钮时我得到空值

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    试试下面的代码:

    为 primefaces 进程更改您的 h:commandButton,partialSubmitajax

    <body>
    <f:view>
        <h:form>
            <h:outputLabel value="Username"></h:outputLabel>
            <h:inputText value="#{loginModel.userName}"></h:inputText>
            <h:outputLabel value="Password"></h:outputLabel>
            <h:inputSecret value="#{loginModel.password}"></h:inputSecret>
            <p:commandButton value="Submit" action="#{loginModel.process}" process="@form" partialSubmit="true" ajax="true" />
        </h:form>
    </f:view>
    </body>
    

    所以你可以在你的过程方法中放置一个断点来查看更新值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-02
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多