如标题所说,我正在尝试从html选择表单中检索选定的项目。我尝试使用以下代码来执行此操作,但是它不起作用!城市值始终为NULL,但地址字段返回正确的值...
form.html:
#{extends '/Admin/admin.html' /}
#{form @save(id)}
#{ifErrors}
<p class="error">
Please correct these errors.
</p>
#{/ifErrors}
<p>
<label>Adresse</label>
<input type="text" name="adress" value="${flash.adress}" id="adress" />
<span class="error">#{error 'adress' /}
</p>
<p>
<label>Ville</label>
<select size="1" >
#{list items:cities, as:'city'}
<option name="city" id="city" value="${flash.city}">${city}</option>
#{/list}
</select>
<span class="error">#{error 'city' /}
</p>
<p>
<input type="submit" value="Publier l'annonce" />
</p>
#{/form}
保存方法:
public static void save(long id, String adress, @Required Place city){
System.out.println(city);
Admin.index();
}
最佳答案
它不会那样工作,应该像这样:
public static void save(long id, String adress, @Required String city){
// in order or so I think...: get the city ID or whatever, process all the data and save
System.out.println(city);
Admin.index();
}
我认为这是您正在寻找的另一种方式:
http://www.playframework.org/documentation/1.1.1/controllers#POJOobjectbinding
关于java - 使用Play Framework从html select表单中检索数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4880929/