This tutorial covers the steps required to add a JavaServer
Faces 2.2 (JSF 2.2)
viewAction component to a web
Time to Complete
Approximately 30 minutes
JSF technology is an user interface (UI) framework for developing Java web applications. It is based on components, events, and Model-View-Controller (MVC) architecture. JSF 2.0 introduced the ability to view parameters. This feature provided a mechanism to process GET requests and pass parameters.
JSF 2.2 defines a new tag,
that extends GET processing further by leveraging a feature from
. This tag is an
UIComponent that executes actions on initial
requests and post-back requests. The
component is declared as a child of the
By default, the
viewAction component is executed
INVOKE_APPLICATION phase. It has an
attribute as other actions in JSF. The
component also provides a
phase attribute, which
can specify the JSF phase for executing the action.
In this tutorial, you modify a sample web application, which
displays a list of products and its details. The product details
are displayed in response to a post-back request. You will use a
viewAction component to display the product details
GET request, resulting in a lighter-weight
Hardware and Software Requirements
The following is a list of hardware and software requirements:
- Java Platform, Standard Edition 7 (Java SE 7; Java SE 7u11 recommended)
- Java Platform, Enterprise Edition (Java EE)
- NetBeans 7.3.1 IDE
- GlassFish 4
Before starting this tutorial, you should:
- Have some experience writing and deploying JSF web applications.
- Have some experience using the
<f:viewParam>tag in a JSF page .
- Have installed NetBeans 7.3.1, Java EE, and GlassFish 4.
- Have started NetBeans.
- Have unzipped the
- Have opened the
ViewActionAppproject in NetBeans.
Running and Examining the
Complete the following steps:
You incorporate the viewAction component into the JSF life cycle on the initial request. It allows the same kind of action methods that are used for post-backs, and it is processed before the entire component tree is built.
Modifying the Home Page
Adding the <f:viewAction>
Running and Verifying the Output of
In this section, you run ViewActionApp and verify its output.
Note: You will see an additional message
displayed twice, in the
ProductDetails page: "The metadata component needs to be
nested within a f:metadata tag. Suggestion: enclose the
necessary components within <f:metadata>". This
is a reported bug
in NetBeans and can be ignored.
In this tutorial, you learned how to:
- Use the <f:viewAction>
tag in a JSF page
- Call actions on GET requests
- Enable lighter-weight calls in a JSF life cycle
The application in this tutorial uses JSF facelets and the JSF 2.2 <f:viewAction> tag. To learn more about these technologies, see the following resources:
blog about JSF 2.2 features
Java EE 7 Tutorial (The tutorial is an excellent source
of information about the technologies included in Java EE 7.)
- To learn more about Java EE 7, visit other OBE tutorials in the Oracle Learning Library.
- Curriculum Developer: Paromita Dutta
- Editor: Susan Moxley
- QA: Veerabhadra Rao Putrevu
To help navigate this Oracle by Example, note the following:
- Hiding Header Buttons:
- Click the Title to hide the buttons in the header. To show the buttons again, simply click the Title again.
- Topic List Button:
- A list of all the topics. Click one of the topics to navigate to that section.
- Expand/Collapse All Topics:
- To show/hide all the detail for all the sections. By default, all topics are collapsed
- Show/Hide All Images:
- To show/hide all the screenshots. By default, all images are displayed.
- To print the content. The content currently displayed or hidden will be printed.
To navigate to a particular section in this tutorial, select the topic from the list.