Martinffx
Martinffx

Reputation: 2476

Play! framework calling the render() action from controller

I've been customising a template generated by the CRUD module and now need to override the save method to save the custom data from the template. I can save all the data, but when I call the render action:

render("Users/show.html", user);

I get a nullPointerException for templates object:

enter image description here

I'm definitely passing the correct user object through because when I run this:

System.out.println(user.toString());
//render("Users/show.html", user);

It writes my user to the console.

Any help will be much appreciated.

Controller View

Play! 1.2.3

Upvotes: 4

Views: 5297

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

Your controller is rendering

render("Users/show.html", user);

but the name of the element in your template is object. It should be user.

UPDATE ON COMMENT

The original templates on CRUd use "object" as an abstraction to the entity under CRUD. If you check the source code of the controller, it says:

//ignoring case when template is not found, alternative also uses object
render(type, object); 

This means that there are two options:

  1. You modified the template breaking this compatibility. It doesn't seem to be the case in your scenario, although we can't see the full code (so it may still be an option)
  2. You modified the controller, changing the objects you send to the template. It seems to be your scenario. So either you fix the template to use user or you rename user to object.

Upvotes: 6

Related Questions