Getting Started with ICEfaces 3

You are viewing an old version (v. 79) of this page.
The latest version is v. 81, last edited on Apr 13, 2012 (view differences | )
<< View previous version | view page history | view next version >>

Getting Started with ICEfaces 3

ICEfaces 3 is the new version of the ICEfaces framework that integrates with JavaServer Faces (JSF) 2. With ICEfaces 3, our goal is to deliver the highest value existing ICEfaces features, as well as important new enhancements, cleanly integrated into the JSF 2 platform. There are a number of ways to take advantage of ICEfaces 3 in your JSF 2 application:

First, add the icefaces.jar to your project. This immediately allows you to take advantage of Direct-to-DOM (D2D) rendering technology. D2D only sends browser DOM changes from the server to the browser, minimizing bandwidth consumption without the need to specify the new "f:ajax" component in your pages. Once the icefaces.jar is added to your project, you can also take advantage of ICEfaces Window Scope and Single Submit features.

After adding the icefaces.jar to your project, you can start adding components:

  • The ACE Components (ICEfaces Advanced Components) are the next-generation of open source ICEfaces components. Currently featuring over 40 components including the industry-leading ace:dataTable, the ACE Components utilize a blend of server-side and client-based rendering techniques to provide a rich, responsive user-experience with reduced network and server-processing requirements.
  • The ICE Components (ICEfaces Components) are based on the original ICEfaces Component Suite in ICEfaces 1.x. The components have been updated to support JSF 2 and more recent versions of ICEfaces. The ICE Components are a complete set of mature JSF components that have benefited from thousands of successful project deployments since their inception. The ICE components are primarily implemented using traditional JSF server-side rendering techniques with limited JavaScript. When combined with ICEfaces automatic-Ajax technology, the ICE Components exhibit extensive partial-page-rendering, providing a rich, dynamic user-experience, even on older legacy browsers.

Finally, you may want to take advantage of asynchronous server-initiated updates using AJAX Push. Adding icepush.jar to your application enables Ajax Push, and allows you to add collaborative capabilities that will revolutionize your application.

Adding ICEfaces 3 to a JSF 2 Project

Direct-to-DOM Rendering

This tutorial makes use of a JSF 2 application. The application consists of a page to add a new Job Applicant:

And a page that displays the applicants:

The clear button in job-applicant.xhtml consists of the following markup:

<h:commandButton id="clearButton" value="Clear">
    <f:ajax event="click" 
            immediate="true" />

Here we see the use of stock JSF tags including the new (as of JSF 2) f:ajax tag. The render="@form" attribute on the f:ajax tag informs JSF that only the form should be rendered after the lifecycle is executed.

Pressing the "Clear" button under these circumstances will generate the following response, which includes the entire form:

<?xml version='1.0' encoding='UTF-8'?>
<update id="form">
<![CDATA[<form id="form" 
    <input type="hidden" name="form" value="form" />
    <div class="header">
        <img src="/gettingStarted/javax.faces.resource/icefaces.png.jsf?ln=images" alt="" />
    <div class="content">
        <div class="menu">
            <input type="button" 
                   onclick="window.location.href='/gettingStarted/applicants.jsf'; return false;" 
                   value="Listing Page" />
        <div class="contentBody">
        <div id="form:table">
                        <label for="form:title">Title</label>
                        <table id="form:title">
                                    <input type="radio" name="form:title" id="form:title:0" value="1" />
                                    <label for="form:title:0"> Dr.</label>
                                    <input type="radio" name="form:title" id="form:title:1" value="2" />
                                    <label for="form:title:1"> Ms.</label>
                                    <input type="radio" name="form:title" id="form:title:2" value="3" />
                                    <label for="form:title:2"> Mrs.</label>
                                    <input type="radio" name="form:title" id="form:title:3" value="4" />
                                    <label for="form:title:3"> Miss</label>
                                    <input type="radio" name="form:title" id="form:title:4" value="5" />
                                    <label for="form:title:4"> Mr.</label>
                        <label for="form:firstName">First Name</label>
                        <input id="form:firstName" type="text" name="form:firstName" value="" />                
                        <label for="form:lastName">Last Name</label>
                        <input id="form:lastName" type="text" name="form:lastName" value="" />                
                        <label for="form:email">Email</label>
                        <input id="form:email" type="text" name="form:email" value="" />
                        <input type="submit" name="form:j_idt49" value="Submit Applicant" />
                        <input id="form:clearButton" 
                               onclick="mojarra.ab(this,event,'click',0,'@form');return false" />
                        <input id="form:cancelButton" 
                               value="Cancel" />
        <div style="clear:both;"></div>
<update id="javax.faces.ViewState"><![CDATA[1247154892383314770:-4900614983041719481]]></update>

ICEfaces renders component markup to a server-side DOM (Document Object Model) that reflects the current client view. Each time the JSF lifecycle runs a DOM comparison is done and, if there are any changes, a concise set of page updates are sent back to the client to be applied to the page. We call this Direct-to-DOM or D2D rendering.

Adding the ICEfaces 3 library to an existing JSF 2 application will provide dynamic partial-page-updates for all compliant components, without the need to specify the "f:ajax" component in your pages.

Make the following change to the "Clear" button as we will no longer need the f:ajax tag (the clearForm method parameter will have to be changed from an AjaxBehaviorEvent to an ActionEvent):

<h:commandButton id="clearButton"
                 immediate="true" />

Now, simply add the icefaces.jar to the application and we have Direct-to-Dom (D2D) rendering applied to the page. When we press the "Clear" button this time, we get the following response:

<?xml version='1.0' encoding='UTF-8'?>
        <update id="javax.faces.ViewState"><![CDATA[1197926691644194967:-7719694313423626628]]></update>

Notice the difference in the amount of markup sent back in the response - and this is for a small form with only four fields. Direct-to-DOM rendering is powerful stuff. The beauty is that from a developer point of view, it takes place automatically under the covers. This is what we call Automatic Ajax. The AJAX is built in to the framework and you do not have to concern yourself with how updates are applied, Direct-to-DOM rendering takes care of it for you.

Single Submit

The Single Submit feature is basically the ability to specify that one component will execute in the JSF lifecycle. ICEfaces 3 Single Submit is similar in intent to ICEfaces Partial Submit, but is an improvement which leverages JSF 2 expanded capabilities.

The <icecore:singleSubmit> tag is a convenient and easy way to Single Submit enable standard h: components, without having to litter the page with <f:ajax> tags. It allows an entire page region to be enabled at once.

Simply add the icecore namespace to your page. In job-applicant.xhtml add the following:


And then nest the tag in your form:

<icecore:singleSubmit submitOnBlur="true" />

All the form fields will now behave as if they have a nested f:ajax tag with the execute="@this" attribute. As the user tabs through fields in the form, the individual fields are executed in the JSF lifecycle and immediate feedback is provided, enhancing the user experience:

In this case, we have tabbed through the first three fields and those components have been executed on the server. They all have the required="true" attribute and because nothing was input in the field, a FacesMessage was automatically generated and output in the page via the h:message tag. We have arrived at the email field without performing a full form submit, but have been able to generate feedback on fields we have already visited.

Window Scope

ICEfaces 3 also features a custom scope called "Window" scope. This custom scope is designed to fill in a gap in the existing scopes available for JSF 2, as it exists for the life of a browser window or tab including surviving reloads and refreshes.

Adding ICEfaces ACE Components

The ICEfaces Advanced Components are next-generation ICEfaces components, based on the all-new Advanced Component Evironment (ACE) component development platform.

Key features of the Advanced Components include:

  • Provide the abilty to leverage powerful JavaScript components while shielding ICEfaces application developers from having to learn/use JavaScript directly.
  • Support client-side functionality to improve component richness, responsiveness, and scalability.
  • Support complete flexibilty in how forms are used with respect to container components, such as TabSet. TabSet allows the use of multiple forms as required, with no limitation that all tabPanes be included in the same form as the tabSet itself.
  • Provide a flexible and consistent approach to UI theming/skinning across all components.
  • Provide support for W3C ARIA accessibility features in all applicable components, including keyboard navigation.

The following Advanced Components are included in the ICEfaces 3 distribution:

  • Animation
  • CheckboxButton
  • DateTimeEntry
  • FileEntry
  • LinkButton
  • PushButton
  • SliderEntry
  • TabSet

To use the components, add the icefaces-ace.jar to your application.

Adding ICEfaces Components

The ICEfaces Components are an ICEfaces 3-compatible version of the ICEfaces 1.x ICEfaces Component Suite.

You should include this library if you want to use the ICEfaces Component Suite components in your application or if you are porting an existing ICEfaces 1.8.x application to ICEfaces 3.

The following ICEfaces Components are included in the ICEfaces 3 distribution:

  • checkbox
  • column
  • columnGroup
  • columns
  • commandButton
  • commandLink
  • commandSortHeader
  • dataExporter
  • dataPaginator
  • dataTable
  • effect
  • form
  • gMap
  • gMapControl
  • gMapDirection
  • gMapGeoXml
  • gMapLatLng
  • gMapLatLngs
  • gMapMarker
  • graphicImage
  • headerRow
  • inputFile
  • inputHidden
  • inputRichText
  • inputSecret
  • inputText
  • inputTextarea
  • loadBundle
  • menuBar
  • menuItem
  • menuItems
  • menuItemSeparator
  • menuPopup
  • message
  • messages
  • outputBody
  • outputChart
  • outputConnectionStatus
  • outputDeclaration
  • outputFormat
  • outputHead
  • outputHtml
  • outputLabel
  • outputLink
  • outputMedia
  • outputProgress
  • outputResource
  • outputStyle
  • outputText
  • panelBorder
  • panelCollapsible
  • panelConfirmation
  • panelDivider
  • panelGrid
  • panelGroup
  • panelLayout
  • panelPopup
  • panelPositioned
  • panelSeries
  • panelStack
  • panelTab
  • panelTabSet
  • panelTooltip
  • portlet
  • radio
  • rowSelector
  • selectBooleanCheckbox
  • selectInputDate
  • selectInputText
  • selectManyCheckbox
  • selectManyListbox
  • selectManyMenu
  • selectOneListbox
  • selectOneMenu
  • selectOneRadio
  • setEventPhase
  • tabChangeListener
  • tree
  • treeNode

To use the components, add the icefaces-compat.jar to your application.

NOTE: If you are using the ICEfaces Components you will also require additional 3rd party libraries. See Appendix A - ICEfaces Library/App. Server Dependencies in the ICEfaces 1.8 Developer's Guide for details.

Adding AJAX Push

To enable Ajax Push with ICEfaces 3, you simply add the icepush.jar library to your application.

ICEfaces 3 provides a new [API] for using Ajax Push from within your application. As a developer, the class you need to be aware of is org.icefaces.application.PushRenderer. The PushRenderer contains the methods to support using Ajax Push in your application. The new API is very similar to the SessionRenderer API from ICEfaces 1.8.x.

Add a session and all associated pages (views) to a group using:

PushRenderer.addCurrentSession(String groupName);

Add only a particular page to a group using:

PushRenderer.addCurrentView(String groupName);

When something of note changes in the application, you can request the client get a notification to get the updates by calling:


You can also use the icecore:push tag to automatically configure Ajax Push behavior on a per-view basis.

<icecore:push group="applicantsGroup"/>

We will use this technique in our tutorial application to update the applicants page after a new job applicant has been added.

First, add icepush.jar to the application. Next, go to applicants.xhtml and add the icecore namespace to the view:


In applicants.xhtml add the icecore:push tag to the page:

<ui:define name="content">
    <icecore:push group="applicantsGroup" />
    <h:dataTable value="#{applicants.applicantsList}"

The icecore:push tag ensures any user viewing this page will receive an update when the PushRenderer renders the 'applicantsGroup'.

The next step is to push an update out to everyone once a new job applicant has been added. In our class we add the following to the addApplicant() method:

This was a simple two step process of associating a push group with a page and then making a render call to that group when the page has changed. Let's see it in action.

Open a browser window in Internet Explorer and one in FireFox. This will create two separate sessions running in our tutorial application. In FireFox, we see a job applicant already added to our applicants list:

In Internet Explorer, we now add a new job applicant:

After the "Submit Applicant" button has been pressed, the Firefox window immediately receives an update via AJAX push:

With AJAX Push added to the application, users receive real-time updates from the server without needing to initiate a request to the server.

Adding icefaces.jar, icefaces-ace.jar and icepush.jar to your JSF 2 applications will equip you with all the tools necessary to create AJAX enabled Rich Internet Applications.

Tutorial Source Code Downloads

Example Source Notes
getting-started-tutorial getting-started-tutorial source code Source code for a basic JSF 2 application ready for ICEfaces enhancements.
In Eclipse Indigo create a Dynamic Web Project, JavaServer Faces V2.0 Project (download Mojarra 2.1.3 jar).
Import the source code in to the project and add the Tomcat 7 runtime to your build path.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.