Reputation: 11524
I am coding a jsf-application. Here is my code:
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>
...
Register.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!!!");
}
My problem is I get as output when I press the button:
null : null :successfully registeres!!!
Why is this?
UPDATE 1------------------------------
ok I used the h:form tag but I still get null back:
here is the cycle I think how the jsf works: First: write in inputText -> the beans reads it -> you can manipulate that value(ex. write it in a list)...
What wrong with that cycle? or my code...
UPDATE 2------------------------------ My setter methods:
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String pwd) {
this.pwd = pwd;
}
They are out of reach, but why?
Upvotes: 1
Views: 2772
Reputation: 15434
Your h:inputText
fields must be inside a form. Try following:
<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>
Now form includes both inputText
fields and commandButton
s
Upvotes: 3