播放框架:scala模板,if语句问题

时间:2014-01-21 19:01:09

标签: java scala if-statement playframework

我无法弄清楚为什么这不起作用,这是我的模板代码:

@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
        }
    }
}

我得到的输出:


1 1

1 2

1 3

2 1

2 2

2 3

3 1

3 2

3 3


我应该去哪里:


1 1已检查

1 2

1 3

2 1

2 2已检查

2 3

3 1

3 2

3 3已检查


我的模特:

public class WorkUser
{
    public String showName;
    public List<Queue> queues = new ArrayList<Queue>();
}


public class Queue extends Model
{
    public long id;
    public String name;
}

我的控制器(我称之为scala模板)

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));
    }
}

似乎问题出现在if语句中但是我无法解决它,我已经尝试了所有。

1 个答案:

答案 0 :(得分:1)

wuQueue("id").value的类型为Stringqueue.id的类型为Long,因此您的等式检查将永远不会通过。考虑将其重写为:

@if(wuQueue("id").value.toLong == queue.id){
  checked
}