[2.1 Java] Form data lost after failing the Validation

51 views
Skip to first unread message

Dark Rider

unread,
Oct 14, 2013, 2:43:19 AM10/14/13
to play-fr...@googlegroups.com
Using Play 2.1 Java version

I have a simple form 

     <div class="row">
<div class="col-md-6">
@inputText(userForm("usercode"), args = 'placeholder -> "User Code",'class -> "form-control input-sm",'_label -> "User Code")
</div>
<div class="col-md-6">
@inputText(userForm("username"), args = 'placeholder -> "User Name",'class -> "form-control input-sm",'_label -> "User Name")
</div>
</div>

When the User submits the Form and if Errors Exists the Form inputted data is lost.

At my controller 

     Form<User> userForm= Form.form(User.class).bindFromRequest();
      if (userForm.hasErrors()) {
                Logger.info("Erros in Form");
                return badRequest(
                        userAdd.render("Add User",userForm)
                );
        }



So after the badRequest, Form data which was entered by user is lost.

Question :

How to retrieve the values back to the form ?

Thanks

       

Mustafa Dumlupinar

unread,
Oct 14, 2013, 5:45:03 AM10/14/13
to play-fr...@googlegroups.com
Sorry My English is bad.

In your controller (here is BankController)

Step 1: You have yo define a form handler, like this;
private final static Form<Bank> dataForm = form(Bank.class);

Step 2:
    public static Result save() {
        Form<Bank> filledForm = dataForm.bindFromRequest();

        if(filledForm.hasErrors()) {
            return badRequest(form.render(filledForm));
        } else {

            Bank model = filledForm.get();
go on...



2013/10/14 Dark Rider <johns...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
İyi çalışmalar...

Mustafa DUMLUPINAR
http://mdpinar.blogspot.com/
Reply all
Reply to author
Forward
0 new messages