I have been working on a site that displays user information on every page. Currently I am retrieving the user details (using an Id stored in the session) and then passing a User object to the render method of each page.
Is there a way to retrieve an object from multiple pages without adding it as a render argument to each method?
Or is this the only/best way to do this?
You can add a @Before method to your controller:
Now all other action methods will automatically have a user object in the renderArgs.
If you want to add this capability to other controller class, then in that class you must have @With:
You can also use “unless” parameter for @Before annotation to exclude some action methods from the @Before fitler. Check out the Play online documentation about controller interception to find out more details