Introduction
With the advent of internet, there has been constant paradigm change from time and again. There are many scripting web languages which came and showed their impact now and then. But the feature I am going to talk about will give a close look to internet as a close friend.In this article, I am trying to showcase the use of AJAX i.e. Asynchronous JavaScript and XML using JSF i.e. JavaServer Faces based components.The pre–requisite for this is some knowledge on JSF and AJAX.There are many JSF implementations for AJAX which help us to provide AJAX features using JSF. Why at all we use JSF and not Struts?. That’s a very typical question people now days ask. Unlike Struts, JSF allows you to create custom components extending standard components. Struts doesn’t provide user to explore the User Interface (UI), but JSF does. There are many typical differences between JSF and Struts.
also read:
- JSF Interview Questions
- Request Processing Lifecycle phases in JSF
- Accessing Web Services from JSF applications
- Navigation model in JSF
But let’s just focus on JSF and AJAX. As we all know AJAX provide us quick response. How? Using asynchronous response / request mechanism. Your request goes to server, which internally does some calculations and provides the response back while you can do other things on the same page. For example, GMAIL. We normally fascinate those things that are friendly to user and as developers try to implement the same in our business applications. So here we go…
Different AJAX implementations for JSF
But each may be different from the other. One may find that one implementation limits in number of components,
other is limited in documentation, support, examples, and learning curve.The best choice which I could make is with the use of JSF Matrix. If one looks, it will give clear picture what components are provided, how much documentation, active forum support, license issues and the like.Evaluating each one of them, I short listed few like Ajax4JSF, RichFaces and IceFaces. My discussion will focus on these three. The reason I have short–listed them, is because of the number of components, active forum, documentation, open license support and active forum to least. I worked with Netbeans 5.5, but they could easily work with other Integrated Development Environments (IDEs) as well.
Ajax – enabled JSF using Ajax4JSF
Introduction to Ajax4JSF
Ajax4JSF is an Open Source framework which adds AJAX capabilities to JSF using component library without having to write JavaScript code in your web page. Its now under Red Hat and Exadel strategic partnership hence its open source and can be used in your application(s) without sharing your own code.
To make JSF application(s) AJAX enabled
conversion facilities and management of static and dynamic resources. The look and feel using Ajax4JSF is highly customizable and easily added to JSF applications.Ajax4JSF follows page–oriented approach rather traditional component–oriented approach. By this it means that you can define events on a page which invokes a Managed Bean, and that will render data on the same page, without page refresh. For a particular component one can invoke action or action listener. By this it means that when action is called a particular event occurs that initiate some logic, but action listener may invoke some set of components to be rendered on a page.
Ajax4JSF Example
Download the latest Ajax4JSF binary/source to embed in your application from Ajax4JSF Downloads. Once that is done, make a Netbeans Web Application project which is JSF enabled. Then update the Netbeans with Ajax4JSF files. In that one has to copy the ajax4jsf.jar and oscache–2.3 .jar files into the WEB–INF/lib folder of existing JSF application.Then in any web page include Ajax4JSF using tag library:
</div>
<div align="justify">
<pre><a4j:form>
<table width="600" border="0">
<tr>
<td width="120" valign="top" rowspan="3" >
<h:selectOneListbox id="list" value="#{backingBean.selectedId}">
<a4j:support event="onclick" action="#{backingBean.changeCurrent}" reRender="info"/>
<f:selectItems value="#{backingBean.selectList}"/>
</h:selectOneListbox>
</td>
<td valign="middle" >
<h:panelGrid id="info" styleClass="panel" rowClasses="celltop, cellmiddle, cellbottom" columns="1">
<h:panelGroup>
<h:outputText value="#{userList.currentUser.prefix}" />
<h:outputText value=" " />
<h:outputText value="#{userList.currentUser.firstName}" />
<h:outputText value=" " />
<h:outputText value="#{userList.currentUser.lastName}" /><br />
<h:outputText value="#{userList.currentUser.address}" />
</h:panelGroup>
<h:panelGroup>
<h:outputText value="#{userList.currentUser.jobTitle}" /><br />
</h:panelGroup>
<h:panelGroup>
<h:outputText value="#{userList.currentUser.phone}" /><br />
<h:outputText value="#{userList.currentUser.mobile}" />
</h:panelGroup>
</h:panelGrid>
</td>
</tr>
</table>
</a4j:form></pre>
</div>
<div align="justify">
Another thing which I find about Ajax4JSF is good that it’s easy to use other AJAX based implementations like Trinidad and JSF implementation like MyFaces. So its kinda blend of different implementations under one hood.
RichFaces
Introduction to RichFaces
To make JSF application(s) AJAX enabled
One can look at the example implementation at Rich Faces Demo and can use the same in one’s code to enhance the AJAX capability.
RichFaces Example
</div> <div align="justify"> <pre><%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%></pre> </div> <div align="justify">
</div>
<div align="justify">
<pre><h:form>
<rich:datascroller for="name" maxPages="3"/>
<rich:spacer height="30"/>
<rich:dataTable width="483" id="name" rows="4" columnClasses="col" value="" var="nameCat">
<f:facet name="header">
<rich:columnGroup>
<h:column>
<h:outputText styleClass="headerText" value="Name"/>
</h:column>
<h:column>
<h:outputText styleClass="headerText" value="Age"/>
</h:column>
</rich:columnGroup>
</f:facet>
<h:column>
<h:outputText value="#{dndDaemon.stName}"/>
</h:column>
<h:column>
<h:outputText value="#{dndDaemon.age}"/>
</h:column>
</rich:dataTable>
</h:form></pre>
</div>
<div align="justify">
ICEFaces
Introduction to IceFaces?
To make JSF application(s) AJAX enabled
IceFaces Example
<%@ taglib uri="http://www.icesoft.com/icefaces/component" prefix="ice" %>
<ice:dataTable
id="inventoryList"
rows="4"
columnClasses="stockColumn, modelColumn, desriptionColumn, odometerColumn, priceColumn"
rowClasses="oddRow, evenRow"
styleClass="tableStyle"
sortColumn="#{inventoryList.sortColumnName}"
sortAscending="#{inventoryList.ascending}"
value="#{inventoryList.carInventory}"
var="item">
<!-- Stock number -->
<ice:column>
<f:facet name="header">
<ice:commandSortHeader
columnName="#{inventoryList.stockColumnName}"
arrow="true" >
<ice:outputText value="#{inventoryList.stockColumnName}"/>
</ice:commandSortHeader>
</f:facet>
<ice:outputText value="#{item.stock}"/>
</ice:column>
<!-- Model number -->
<ice:column>
<f:facet name="header">
<ice:commandSortHeader
columnName="#{inventoryList.modelColumnName}"
arrow="true" >
<ice:outputText value="#{inventoryList.modelColumnName}"/>
</ice:commandSortHeader>
</f:facet>
<ice:outputText value="#{item.model}"/>
</ice:column>
<!-- Description -->
<ice:column>
<f:facet name="header">
<ice:commandSortHeader
columnName="#{inventoryList.descriptionColumnName}"
arrow="true" >
<ice:outputText value="#{inventoryList.descriptionColumnName}"/>
</ice:commandSortHeader>
</f:facet>
<ice:outputText value="#{item.description}"/>
</ice:column>
<!-- Odometer reading -->
<ice:column>
<f:facet name="header">
<ice:commandSortHeader
columnName="#{inventoryList.odometerColumnName}"
arrow="true" >
<ice:outputText value="#{inventoryList.odometerColumnName}"/>
</ice:commandSortHeader>
</f:facet>
<ice:outputText value="#{item.odometer}"/>
</ice:column>
<!-- Price number -->
<ice:column>
<f:facet name="header">
<ice:commandSortHeader
columnName="#{inventoryList.priceColumnName}"
arrow="true" >
<ice:outputText value="#{inventoryList.priceColumnName}"/>
</ice:commandSortHeader>
</f:facet>
<ice:outputText value="#{item.price}"/>
</ice:column>
</ice:dataTable>
<ice:panelGrid columns="2">
<!-- Paginator with page controls -->
<ice:dataPaginator id="dataScroll_3"
for="inventoryList"
paginator="true"
fastStep="3"
paginatorMaxPages="4">
<f:facet name="first">
<ice:graphicImage
url="./xmlhttp/css/xp/css-images/arrow-first.gif"
style="border:none;"
title="First Page"/>
</f:facet>
<f:facet name="last">
<ice:graphicImage
url="./xmlhttp/css/xp/css-images/arrow-last.gif"
style="border:none;"
title="Last Page"/>
</f:facet>
<f:facet name="previous">
<ice:graphicImage
url="./xmlhttp/css/xp/css-images/arrow-previous.gif"
style="border:none;"
title="Previous Page"/>
</f:facet>
<f:facet name="next">
<ice:graphicImage
url="./xmlhttp/css/xp/css-images/arrow-next.gif"
style="border:none;"
title="Next Page"/>
</f:facet>
<f:facet name="fastforward">
<ice:graphicImage url="./xmlhttp/css/xp/css-images/arrow-ff.gif"
style="border:none;"
title="Fast Forward"/>
</f:facet>
<f:facet name="fastrewind">
<ice:graphicImage url="./xmlhttp/css/xp/css-images/arrow-fr.gif"
style="border:none;"
title="Fast Backwards"/>
</f:facet>
</ice:dataPaginator>
<!-- Display counts about the table and the currently displayed page -->
<ice:dataPaginator id="dataScroll_2" for="inventoryList"
rowsCountVar="rowsCount"
displayedRowsCountVar="displayedRowsCount"
firstRowIndexVar="firstRowIndex"
lastRowIndexVar="lastRowIndex"
pageCountVar="pageCount"
pageIndexVar="pageIndex">
<ice:outputFormat
value="{0} cars found, displaying {1} car(s), from {2} to {3}. Page {4} / {5}."
styleClass="standard">
<f:param value="#{rowsCount}"/>
<f:param value="#{displayedRowsCount}"/>
<f:param value="#{firstRowIndex}"/>
<f:param value="#{lastRowIndex}"/>
<f:param value="#{pageIndex}"/>
<f:param value="#{pageCount}"/>
</ice:outputFormat>
</ice:dataPaginator>
</ice:panelGrid>
</center>






July 16, 2007
Java Server Faces (JSF), Web Frameworks