Reputation: 139
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.
alert(document.forms[0].mySelectField.value)
before submit in the view (I can see the value)play reload, play clean, play clean-all, play complile
(No use)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
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