maximus
maximus

Reputation: 11544

:inputText only gives null back?(setter are not reached)

i am coding a register-form in jsf:

in the *.xhtml file:

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

in the bean:

public String getPassword() {
    return password;
}

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

I set a breakpoint and noticed that my setter are not reached?

why?

++++1.Update++++++

Register.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.Update++++++

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

++++3.Update++++++ my form code:

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

Upvotes: 0

Views: 914

Answers (2)

waxwing
waxwing

Reputation: 18783

I noticed you have immediate="true" on your commandButton. This seems like a probable cause why your model is not being updated.

This blog entry seems to describe a similar, if not the same, problem. Now, there are some workarounds for this, either you can get the submitted value directly from the component by using the bind attribute, or you can use immediate="true" on the input components as well, but I think the best solution would be not to use immediate on your submit button unless you really need it.

Upvotes: 0

Daniel
Daniel

Reputation: 37061

Place your h:commandButton and the <h:inputText in the same form that you are trying to submit...

Upvotes: 1

Related Questions