Friday, 23 August 2013

Play 2.0 java - get list of models from http context

Play 2.0 java - get list of models from http context

I store a list of models in Http.context, then I'm not able to loop
through it in the view.
Index action :
@With(MembershipAction.class)
public static Result index() {
...
Action composition :
public class MembershipAction extends Action.Simple {
@Override
public Result call(Context ctx) throws Throwable {
Member member = Membership.getUser();
if (member != null) {
// MGroup.findInvolving(member)= List<play.db.ebean.Model>
// code : find.where().eq("members.id", member.id).findList();
ctx.args.put("groups", MGroup.findInvolving(member));
}
return delegate.call(ctx);
}
}
Template view #1 :
@ctx().args.get("groups")
Output : BeanList size[6] hasMoreRows[false] list[models.MGroup@51,
models.MGroup@3d, models.MGroup@2a, models.MGroup@29, models.MGroup@15,
models.MGroup@1]
Template view #2 (not working) :
@for(group <- ctx().args.get("groups") ){
@group.name
}
Output : Compilation Error / value map is not a member of Object
NOTE : The method described here didnt work either : How to avoid passing
parameters everywhere in play2?
Trying the snippet "@Menus" was unknown...

No comments:

Post a Comment