Play Framework: mixing Java and Scala controller / views

The .enablePlugins (PlayScala) parameter is set in the built.sbt file, which sets my project to scala.

Now I want to use Java. I found that there are two versions of data.Form (play.data._ and import play.api.data._). Therefore, I used a complete list of parameters 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 helper functions, and I don’t know what is the full name for the helper to work with play.data.Form (Java).

Is there a way to use helper functions for Java even if the project is set to scala?

Edit:

The error message for this line -> @ helper.inputText (loginForm ("username")) <<is:

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

Edit:

Here is the relevant part of my Java controller.

 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)); } 
+7
java scala playframework
source share
1 answer

PlayMagicForJava involves implicitly converting your play.data.Form.Field to play.api.data.Field

 implicit def javaFieldtoScalaField(jField: Field): Field 

Implicit conversion of a Java play form form to a valid Scala form field.

api link

0
source share

All Articles