dvlpr
dvlpr

Reputation: 139

Play 2.1.1 - Not binding simple select

I have a frustrating problem with Play 2.1.1

I revisited an existing page which was working fine and added a couple of simple select statements (not multi-select). No matter what I do the values are not getting bound to the Form on bindRequest()

Here is what I have done until now.

  1. Did alert(document.forms[0].mySelectField.value) before submit in the view (I can see the value)
  2. Ran: play reload, play clean, play clean-all, play complile (No use)
  3. If I replace the select statement with an text box of same name Play binds it okay.
  4. Printed request().body().asFormUrlEncoded() in Controller. It does not even see the select field (except in case of point 3 above).

mySelectField in MyForm is private. But it has public getter/setter.

It is a simple problem but I have been at this for 4 hours now. Any suggestions? Thanks.

View:

<input type="text" value="Y" name="mySelectField" />
<!--
<select id="mySelectField" name"mySelectField" style="width: 180px;">
 <option value="">All</option>                                               
 <option value="Y">Yes</option>
<option value="N">No</option>
</select>   
--> 

Form:

private String mySelectField;
public String getMySelectField() {
    return mySelectField;
}
public void setMySelectField(String mySelectField) {
    this.mySelectField= mySelectField;
}

Controller:

Form<MyForm> myFormP = Form.form(MyForm.class); 
MyForm myForm = myFormP.bindFromRequest().get();
System.out.println("B. "+myForm.getMySelectField());
System.out.println("Form: "+request().body().asFormUrlEncoded());

Upvotes: 1

Views: 53

Answers (1)

Julien Tournay
Julien Tournay

Reputation: 544

As far as Play is concerned, there's no difference between a text field and a select. Both are encoded values in the request. I suggest you use the dev tools in chrome or firefox to see the differences in the submitted requests.

Upvotes: 1

Related Questions