I can't figure out why this doesn't work, here is my template code:
@workuserForm: Form[WorkUser],queues: List[Queue])
@import helper._
@import helper.twitterBootstrap._
@main("User Form"){
@helper.form(action = routes.Users.saveWorkUser() , 'class -> "form-horizontal"){
@for(queue <- queues){
@repeat(workuserForm("queues"), min = 0){ wuQueue =>
@wuQueue("id").value
@queue.id
@if(wuQueue("id").value == queue.id){
checked
}
}
}
The output I get:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Where I should get:
1 1 checked
1 2
1 3
2 1
2 2 checked
2 3
3 1
3 2
3 3 checked
My models:
public class WorkUser
{
public String showName;
public List<Queue> queues = new ArrayList<Queue>();
}
public class Queue extends Model
{
public long id;
public String name;
}
My controller ( where I call the scala template)
public class Users extends Controller
{
private static final Form<WorkUser> workuserForm = Form.form(WorkUser.class);
public static Result newWorkUser()
{
List<Queue> queues = Queue.findAll();
WorkUser workUserAux = new WorkUser();
workUserAux.queues = queues;
Form<WorkUser> filledForm = workuserForm.fill(workUserAux);
return ok(views.html.workUser.render(filledForm,queues));
}
}
It seems that the problem is in the if statement but i can't solve it , I've tried all.
wuQueue("id").value
is of type String
and queue.id
is of type Long
, so your equality check will never pass. Consider rewriting it as:
@if(wuQueue("id").value.toLong == queue.id){
checked
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.