gpt4 book ai didi

java - :inputText only gives null back?(未到达 setter )

转载 作者:行者123 更新时间:2023-12-01 15:23:47 25 4
gpt4 key购买 nike

我正在 jsf 中编写一个寄存器表单:

在 *.xhtml 文件中:

   <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>
</fieldset>
</h:form>

在 bean 中:

public String getPassword() {
return password;
}

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

我设置了一个断点,发现我的 setter 没有到达?

为什么?

++++1.更新++++++

注册.java:

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;

@ManagedBean(name="Register")
@SessionScoped
public class Register implements Serializable{

private String password = "Fill in!";

/** Creates a new instance of Customer */
public Register() {
//null
}

public String getPassword() {
return password;
}

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

++++2.更新++++++

<div id="buttons">
<h:commandButton id="enter" accesskey="r" value="Registrieren" action="#{Register.registerPlayer()}" immediate="true"/>
</div>

++++3.更新++++++我的表单代码:

<!-- Login-->


<h:form>
<h3><span xml:lang="en">Login</span> Daten </h3>
<div class="formblock">

<fieldset>
<div>
<h:outputLabel class="Float" for="username" value="Username"/>
<h:inputText id="username" rendered="true" value="#{Register.username}" label="Username">
</h:inputText>
</div>

<div>
<h:outputLabel class="Float" for="password" value="Passwort"/>
<h:inputSecret id="password" rendered="true" value="#{Register.password}" label="Passwort">
</h:inputSecret>
</div>
</fieldset>

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

最佳答案

放置您的 h:commandButton<h:inputText与您尝试提交的表单相同...

关于java - :inputText only gives null back?(未到达 setter ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10480909/

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