HTML and CSS Reference
In-Depth Information
<f:viewAction />
A new view metadata tag, <f:viewAction /> , was introduced in JSF 2.2. The purpose of the tag is to allow for
preprocessing before the response is rendered. Preprocessing may include fetching data from the database or checking
conditions that alter the navigation flow. As an example you could use the viewAction to load the entity to display from
the database. If the requested entity does not exist in the database, you can redirect the user to a view stating that the file
no longer exists. Listing 5-25 shows a Facelets file that has a viewAction that loads a record upon viewing the page.
Listing 5-25. Facelet View Using f:viewAction to Load the Record to Display
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" " >
<html xmlns=" "
xmlns:h=" "
xmlns:f=" " >
<f:viewParam name="id" value="#{}" />
<f:viewAction execute="#{recordDisplay.load}" onPostback="false" />
<title>View Record #{}</title>
<h1>Record ##{}</h1>
<h:panelGrid columns="2">
<h:outputText value="Name:" />
<h:outputText value="#{}" />
<h:outputText value="Description:" />
<h:outputText value="#{recordDisplay.record.description}" escape="false" />
Listing 5-26 contains the navigation rule that should be used when trying to access a non-existing record.
The rule states that if false is returned the browser should be redirected to the /not-found.xhtml file.
Listing 5-26. Navigation Case in faces-config.xml that Redirects the User if the Entity Could Not Be Loaded
<redirect />
Search WWH ::

Custom Search