Magazine
 
JSF Application
 

Immediate Event Handling Example

Event Handling is one of the important concepts in JSF. This section provides a simple JSF application, which explains how to implement “immediate” event handling in JSF. Immediate event handling is useful in cases where you do not need to validate an entire page to process
a user input. Normally, the event handler for components executes in the invoke application phase. But when the “immediate” attribute is set to “true” for the component then event executes in the apply request values phase and
forces JSF to skip directly to the render response phase leaving all intermediate phases of the life cycle. In this case the whole form is not validated before event handler is invoked and displays response directly.

This application takes both types of events i.e. Value Change Event and Action Event. When the user changes its choice from the list of song, a value change event occurs which displays detailed information of the selected song and when it clicks a radio button to select a category
of books, a value change listener event is fired for this component which displays subcategory of the selected category i.e. displays a list of books of the selected category. When the user clicks the button labeled “Show All Selected” then an action event registered for the component is fired which displays the items selected

This application can be downloaded as zip format from the link provided in every page of the section. Extract this file and place the folder in the webapp directory of Tomcat server. Requesting the url http://localhost:8080/
jsfImmediateEventapp
through the browser will display “select.jsp” page where you can test the events. This page is shown as below.

 

 

When the user submits the above URL “index.jsp” page is called which delegates the control to the “select.jsp” page.

index.jsp

<html>
<body>
<jsp:forward page=”/pages/select.jsf”/>
</body>
</html>

select.jsp

<%@ taglib uri=”http://java.sun.com/jsf/
html” prefix=”h” %>
<%@ taglib uri=”http://java.sun.com/jsf/
core” prefix=”f” %>
<html>
<head>
<title>JSF Immediate Event Handling
Example</title>
</head>
<body>
<f:view>
<h:form id=”songForm”>
</br>
<h:selectOneMenu id=”songList”
value=”#{backingBean.selectedSong}”
valueChangeListener=
”#{backingBean.processValueChange1}”
immediate=”true”
onchange=”this.form.submit()”>

Feb 2008 | Java Jazz Up | 54
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,

Download PDF