简体   繁体   English

Play Framework:混合Java和Scala控制器/视图

[英]Play Framework: Mixing Java and Scala controller/views

There is a setting .enablePlugins(PlayScala) in the built.sbt file that sets my project to scala. 在build.sbt文件中有一个设置.enablePlugins(PlayScala),它将我的项目设置为scala。

Now I want to use Java as well. 现在我也想使用Java。 I found that there are two versions of data.Form (play.data._ and import play.api.data._). 我发现有两个版本的data.Form(play.data._和import play.api.data._)。 So I used the fully qualified type for the parameter list. 所以我使用了参数列表的完全限定类型。

@(loginForm: play.data.Form[User_LoginForm])

@import helpers._

@helper.form(action = routes.ApplicationJava.login(), 'id -> "loginForm") {
@helper.inputText(loginForm("username"))
@helper.inputPassword(loginForm("password"))
}

But now I have the same problem with the helper functions and I don't know what the fully qualified name for helper is so that they work with play.data.Form (Java). 但是现在我对辅助函数有同样的问题,我不知道helper的完全限定名是什么,以便它们与play.data.Form(Java)一起使用。

Is there a way to use the helper functions for Java even when the project is set to scala? 有没有办法使用Java的辅助函数,即使项目设置为scala?

Edit: 编辑:

The error message for this line >> @helper.inputText(loginForm("username")) << is: 此行的错误消息>> @helper.inputText(loginForm(“username”))<<是:

type mismatch; found : play.data.Form.Field required: play.api.data.Field

Edit: 编辑:

Here is the corresponding part of my Java contoller. 这是我的Java控制器的相应部分。

public static Result showForm() {

    Form<User_LoginForm> userForm = play.data.Form.form(User_LoginForm.class);
    User_LoginForm ulf = new User_LoginForm();
    ulf.username = "abc";
    userForm = userForm.fill(ulf);

    return ok(views.html.userLoginJava.render(userForm));
}

PlayMagicForJava is supposed to implicitly convert your play.data.Form.Field into play.api.data.Field PlayMagicForJava应该隐式将你的play.data.Form.Field转换为play.api.data.Field

implicit def javaFieldtoScalaField(jField: Field): Field

Implicit conversion of a Play Java form Field to a proper Scala form Field. 将Play Java表单字段隐式转换为适当的Scala表单字段。

link to api 链接到api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM