java - 在 Play 中使用@select! Framework 2.3模板和Java

标签 java scala playframework-2.0

我正在尝试在 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 。这就是原因,它显示此错误需要 Seq[(String, String)]

要解决此问题,您必须通过 options 包装 deviceList,让助手知道 deviceListselectoptions

所以应该像下面这样。

@helper.select(myForm("device"), options(deviceList),'_label -> "Perform on device")

关于java - 在 Play 中使用@select! Framework 2.3模板和Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28303823/

相关文章:

java - NDK 在 Android 中如何工作——NDK、JNI 等的使用顺序是什么?

scala - `trait` 的依赖注入(inject)

performance - Spark 性能 - 如何并行化大循环?

java - 如何将回调转换为 Promise

java - Spring Boot Maven 不会构建可执行 Jar,因为它发现重复项

java - Artifact 从 Maven 中心消失?

Java API 总结

scala - 已弃用 sbt 包中的特征构建 : Use . sbt 格式

security - 使用 cookie 和 java 创建非常安全的登录

scala - 从 Play 2 Scala Controller 提供静态/public/文件