0

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>
maximus
  • 11,264
  • 30
  • 93
  • 124
  • Could you please show us the `Register` bean's code – jmj May 07 '12 at 11:14
  • what data you enter and submit the form ? I hope it validates the validation you specified – jmj May 07 '12 at 11:21
  • @JigarJoshi Yes, I think that's his problem too. Btw, bean naming convention is to start with lower-case letter. In your case the class name is `Register`. Without specifying the name, JSF automatically converts it to `register` with lower-case letter. So there is no need to specify it unless you want to have it different, like `registerBean`. – Fallup May 07 '12 at 11:35
  • 1
    @user1248720 do you have comandButton ? to submit the values? – Daniel May 07 '12 at 11:36
  • @Fallup OP has already specified bean name with annotation (apart from conventions, there is no issue with that) – jmj May 07 '12 at 11:39
  • @JigarJoshi Ofcourse, I know that he specified the bean name in annotation and I'm not saying there is any issue with that. Just wanted to clarify when he needs to do that + showing convention. – Fallup May 07 '12 at 11:50
  • btw thx for all your answers!!! what do you mean by validation? h:inputText has a password, but its a string element so is that validation enough? – maximus May 07 '12 at 12:02
  • You have placed `` as an implicit validation. It means if you don't enter password between 3 to 8 chars the validation will fail and your setter wont get called. Try to enter 4 char password, if it is not working you are not submitting the form at all as @Daniel stated. – Fallup May 07 '12 at 12:20
  • kk i deleted the validators and used one form element for all my inputText Elements. But i get as comment in netbeans: The attribute action is not defined in the component interface!! – maximus May 07 '12 at 12:27
  • There is nothing bad on using validation... Please post related xhtml code. Seems like you are missing the basics. – Fallup May 07 '12 at 12:34
  • You are skipping the whole Apply Request Value phase - Update Model value phase with `immediate="true"`, so your values wont get updated. Remove that. – Fallup May 07 '12 at 12:44
  • @user1248720 not sure how reliable the netbeans warning in this case , does the submiting works for you if you place all in one form? – Daniel May 07 '12 at 13:19
  • the immediate="true" was the mistake!!! thx all to your answers!!! and thx Fallup!!! – maximus May 07 '12 at 20:20

2 Answers2

1

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

Daniel
  • 36,833
  • 10
  • 119
  • 200
0

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.

waxwing
  • 18,547
  • 8
  • 66
  • 82
  • I just scanned the comments and I missed that. Why didn't you post it as an answer? – waxwing May 07 '12 at 15:48
  • Because it was related to discussion in comments and I'm not sure if it is the main root of the problem. I would post it as answer after his confirmation of success :P, or maybe not, I don't care about reputation that much. – Fallup May 07 '12 at 16:20