6-10. Invoking a Managed Bean Action on Render

Problem

You want to invoke an application-specific action when a JSF view is rendered.

Solution

Add an f:metadata tag to the head of your view, and then embed a viewAction component within it, specifying the action method you want to invoke. This technique can be handy for executing back-end code prior to loading a page. As such, this technique can also be used to replace the f:event tag in order to create a bookmarkable URL. In this example, the Acme Bookstore author bio page has been updated so that it can be directly linked to, passing in an author’s last name as a view parameter via the URL. The viewAction component is executed before the view is rendered, invoking the business logic to search ...

Get Java EE 7 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.