Getting Started with ICEfaces 2

You are viewing an old version (v. 21) 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 2

ICEfaces 2 is the new version of the ICEfaces framework that integrates with JavaServer Faces (JSF) 2. With ICEfaces 2, 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 2 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 "ICEfaces Advanced Components" are next-generation ICEfaces components. They are based on the all-new Advanced Component Environment (ACE) component development platform which implements a consistent approach to component authoring, meta-data management, and automates common component development tasks and optimizations.
  • ICEfaces 2 provides a compatible component library based on the ICEfaces 1.x component suite. This set of components are referred to as "ICEfaces Components" and immediately allow developers to build ICEfaces 2 applications with a mature AJAX component suite.

Finally, you may want to take advantage of asynchronous server-initiated updates using ICEpush. ICEpush draws on years of expertise with Ajax Push in ICEfaces/JSF and gives applications the power of real-time, web-based collaboration.

This tutorial will discuss the following topics related to ICEfaces 2:

  • [Adding ICEfaces 2 to a JSF 2 Project]
    • [Direct-to-DOM (D2D) Rendering]
    • [Single Submit]
    • [Window Scope]
  • [Adding ICEfaces ACE Components]
  • [Adding ICEfaces Components]
  • [Adding ICEpush]
  • [Tutorial Source Code Download]

Adding ICEfaces 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" render="@form" listener="#{applicantController.clearForm}" immediate="true" />

Here we see the use of stock JSF tags including the new 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"?>
<partial-response><changes><update id="form"><![CDATA[
<form id="form" name="form" method="post" action="/jobApplication/job-applicant.jsf" 
<input type="hidden" name="form" value="form" />
<div class="header">
    <img src="/jobApplication/javax.faces.resource/icefaces.png.jsf?ln=images" alt="" /></div>
<div class="content">
<div class="menu">
    <input type="button" onclick="window.location.href='/jobApplication/applicants.jsf'; return false;" 
           value="Listing Page" />
<div class="contentBody">
    <div id="form:table" style="background-color:;">
	    	<td><label for="form:title">Title</label></td>
                    <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:input" style="float:left;">First Name</label>
                    <input id="form:firstName:input" type="text" name="form:firstName:input" value="" 
                           style="float:left;" />
                    <span id="form:firstName:msg"></span>
                    <label for="form:lastName:input" style="float:left;">Last Name</label>
                    <input id="form:lastName:input" type="text" name="form:lastName:input" value="" 
                           style="float:left;" />
                    <span id="form:lastName:msg"></span>
                    <label for="form:email:input" style="float:left;">Email </label>
                    <input id="form:email:input" type="text" name="form:email:input" value="" 
                           style="float:left;" onblur="mojarra.ab(this,event,'blur',0,'form:email:msg')" />
                    <span id="form:email:msg"></span>
                    <input type="submit" name="form:j_idt50" value="Submit Applicant" />
                    <input id="form:clearButton" type="submit" name="form:clearButton" value="Clear" 
                           onclick="mojarra.ab(this,event,'click',0,'@form');return false" />
                    <input id="form:cancelButton" type="submit" name="form:cancelButton" value="Cancel" />
<div style="clear:both;"></div>
<update id="javax.faces.ViewState">

ICEfaces 2 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 2 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.

Simply add the icefaces.jar to the application and we have Direct-to-Dom (D2D) rendering applied to the page. Now, when we press the "Clear" button, we get the following response which only updates two hidden fields:

<?xml version="1.0" encoding="utf-8"?>
<partial-response><changes><update id="v3wbj72"><![CDATA[
<form action="/jobApplication/job-applicant.jsf" id="v3wbj72" method="post" name="v3wbj72">
    <input name="v3wbj72" type="hidden" value="v3wbj72" />
    <input autocomplete="off" id="javax.faces.ViewState" name="javax.faces.ViewState" type="hidden" 
           value="-6647367167940831220:-1927413051417630450" />
<update id="javax.faces.ViewState">

With Direct-to-DOM rendering, we no longer need the f:ajax tag nested in our "Clear" button:

<h:commandButton id="clearButton" value="Clear" listener="#{applicantController.clearForm}" 
                 immediate="true" />

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 'Application Level 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 only one component will execute in the JSF lifecycle. ICEfaces 2 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 namespace to your page:


And then nest the tag in your form:

<icecore:singleSubmit />

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.

Window Scope

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

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 2 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 2-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 2.0.

  • 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.

<java version="1.6.0_21" class="java.beans.XMLDecoder"> 
  <object class="java.util.ArrayList"> 
    <void method="add"> 
      <object class="com.icesoft.icefaces.tutorial.component.autocomplete.City"> 
        <void property="areaCode"> 
        <void property="city"> 
        <void property="country"> 
        <void property="state"> 
          <string>New York</string> 
        <void property="stateCode"> 
        <void property="zip"> 

In this case, we have encapsulated the options available to the user in a zipped xml file that is deployed with the applications. Options available to the user could also be retrieved from a database.

Tutorial Source Code Downloads

Example Source Notes
autocomplete-tutorial [autocomplete-tutorial source code|^|Download Source Code] Simple example on how to use the Auto-Complete component.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.