![](/img/trans.png)
[英]Play Framework 2.3 Java : FileNotFoundException when specifying configuration file
[英]Use of @select in a Play! Framework 2.3 template and Java
我正在尝试在Play中使用“选择”表单元素! 2.3,并且无法使其正常工作。 我可以为模板提供什么? 目前我有这个:
public static Result add(Long sensorId) {
Form<Action> myForm = Form.form(Action.class);
Sensor sensor = Sensor.find.byId(sensorId);
Action action = new Action();
action.actionUp = true;
action.sensor = sensor;
myForm.fill(action);
HashMap<String, String> devices = new HashMap<>();
for(Device device : Device.find.all()){
devices.put(device.id.toString(), device.name);
}
return ok(editView.render(myForm, action, devices));
}
和模板:
@(myForm: Form[models.Action], action: models.Action, deviceList: HashMap[String, String])
@helper.select(myForm("device"), deviceList,'_label -> "Perform on device")
但这不起作用,因为它期望使用Seq [(String,String)]。 虽然我找不到在Java中创建该方法的方法,但是非常感谢任何帮助!
表单助手不会知道,如果您直接将deviceList
放置在select
中,最后,它会期待您的options
。 这就是原因,它表明此错误expects a Seq[(String, String)]
。
为了解决这个问题,您必须用options
包装deviceList
,以使助手知道deviceList
是select
的options
。
所以应该像下面这样。
@helper.select(myForm("device"), options(deviceList),'_label -> "Perform on device")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.