0
votes

I have a function in a controller that returns a list of User model records - I am using the PlayStartApp template:

public Result getAllUsers() {
    List<User> users = User.find.all();
    return ok(searchusers.render(form(Login.class, users)));
}

This function works correctly and returns a List object.

I also have a view (html page) set with this to pass the object to the view:

@(loginForm: Form[Application.Login], userList: java.util.List[User])

When I compile in activator on the command line, I receive this error message:

[PlayStartApp] $ compile
[info] Compiling 1 Scala source and 1 Java source to C:\WebDev\git\PlayAuthentic
ate\target\scala-2.10\classes...
[error] C:\WebDev\git\PlayAuthenticate\app\controllers\Application.java:209: met
hod render in class views.html.searchusers cannot be applied to given types;
[error]   required: play.data.Form<controllers.Application.Login>,java.util.List
<models.User>
[error]   found: play.data.Form<controllers.Application.Login>
[error]   reason: actual and formal argument lists differ in length
[error] searchusers.render
[error] C:\WebDev\git\PlayAuthenticate\app\controllers\Application.java:215: no
suitable method found for form(java.lang.Class<controllers.Application.Login>,ja
va.util.List<models.User>)
[error]     method play.data.Form.<T>form(java.lang.Class<T>,java.lang.Class<?>)
 is not applicable
[error]       (cannot infer type-variable(s) T
[error]         (argument mismatch; java.util.List<models.User> cannot be conver
ted to java.lang.Class<?>))
[error]     method play.data.Form.<T>form(java.lang.String,java.lang.Class<T>,ja
va.lang.Class<?>) is not applicable
[error]       (cannot infer type-variable(s) T
[error]         (actual and formal argument lists differ in length))
[error]     method play.data.Form.<T>form(java.lang.String,java.lang.Class<T>) i
s not applicable
[error]       (cannot infer type-variable(s) T
[error]         (argument mismatch; java.lang.Class<controllers.Application.Logi
n> cannot be converted to java.lang.String))
[error]     method play.data.Form.<T>form(java.lang.Class<T>) is not applicable
[error]       (cannot infer type-variable(s) T
[error]         (actual and formal argument lists differ in length))
[error] form
[info] Some messages have been simplified; recompile with -Xdiags:verbose to get
 full output
[error] (compile:compileIncremental) javac returned nonzero exit code

I reviewed this post, but I am still having the same issue: Play Framework 2.2.1 - Compilation error: "method render in class index cannot be applied to given types;"

Any help would be great!

EDIT: I removed the Login form. Code is now:

public Result getAllUsers() {
    List<User> users = User.find.all();
    return ok(searchusers.render(users));
}

My view now has:

@(userList: List[User])


@main(null) {

<ul>
@for(user <- userList) {
  <li>@user.fullname</li>
} 
</ul>

}

I am receiving this when compiling:

[error] C:\WebDev\git\PlayAuthenticate\app\controllers\Application.java:209:  no
 instance(s) of type variable(s) T exist so that play.data.Form<T> conforms to java.util.List<models.User>
1
Looks like you are using the wrong view file - pamu

1 Answers

2
votes

Change this line

ok(searchusers.render(form(Login.class, users)))

to

ok(searchusers.render(form(Login.class), users))

For clarity sake

Form[Application.Login] loginForm = form(Login.class)

ok(searchusers.render(loginForm, users))

You have to pass form as first argument and users as second argument, but you are trying to pass Login.class and users to form which is wrong.