gpt4 book ai didi

java - h :inputText - does not put input in beans?

转载 作者:行者123 更新时间:2023-11-29 06:00:07 24 4
gpt4 key购买 nike

我正在编写一个 jsf 应用程序。这是我的代码:

register.xhtml:

        <fieldset>
<div>
<h:outputLabel class="Float" for="username" value="Username"/>
<h:inputText id="username" rendered="true" value="#{Register.username}" label="Username">
<f:validateLength minimum="3" maximum="8"/>
</h:inputText>
</div>
<div>
<h:outputLabel class="Float" for="password" value="Passwort"/>
<h:inputText id="password" rendered="true" value="#{Register.password}" label="Passwort">
<f:validateLength minimum="3" maximum="8"/>
</h:inputText>
</div>
</fieldset>

<div id="buttons">
<h:form id="buttons">
<h:commandButton id="enter" accesskey="r" value="Registrieren" action="#{Register.registerPlayer()}" immediate="true"/>
<h:outputText value="#{msg.wrongpwd}" rendered="#{loginCtrl.loginfailed}" style="color: red"/>
<h:messages style="color: red"/>
</h:form>
</div>
</form>
...

注册.java:

public String getUsername() {
return username;
}

public String getPassword() {
return pwd;
}

public void registerPlayer() {
this.nameList.add(getUsername());
this.passwordList.add(pwd);
System.out.println(getUsername() + " : " + pwd + " :successfully registered!!!");
}

我的问题是按下按钮时得到的输出是:

null : null : 注册成功!!!

这是为什么?

更新 1--------------------------------

好的,我使用了 h:form 标签,但我仍然返回 null:

这是我认为 jsf 工作原理的循环:首先:写入 inputText -> bean 读取它 -> 你可以操作该值(例如,将其写入列表)...

这个循环有什么问题?或者我的代码...

更新 2--------------------------------我的二传手方法:

public void setUsername(String username) {
this.username = username;
}
public void setPassword(String pwd) {
this.pwd = pwd;
}

他们遥不可及,但为什么呢?

最佳答案

您的 h:inputText 字段必须在表单内。尝试以下操作:

<h:form>
<fieldset>
<div>
<h:outputLabel class="Float" for="username" value="Username"/>
<h:inputText id="username" rendered="true" value="#{Register.username}" label="Username">
<f:validateLength minimum="3" maximum="8"/>
</h:inputText>
</div>
<div>
<h:outputLabel class="Float" for="password" value="Passwort"/>
<h:inputText id="password" rendered="true" value="#{Register.password}" label="Passwort">
<f:validateLength minimum="3" maximum="8"/>
</h:inputText>
</div>
</fieldset>

<div id="buttons">
<h:commandButton id="enter" accesskey="r" value="Registrieren" action="#{Register.registerPlayer()}" immediate="true"/>
<h:outputText value="#{msg.wrongpwd}" rendered="#{loginCtrl.loginfailed}" style="color: red"/>
<h:messages style="color: red"/>
</div>
</h:form>

现在表单包括 inputText 字段和 commandButton

关于java - h :inputText - does not put input in beans?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10474245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com