JSF Components – A Quick Example Using ICEFaces

by on December 26, 2012 9:01 am

This is a continuation of my previous entry on component based java frameworks. In this post, I would like to give a couple of examples of the kinds of components that can be used to quickly bring up a user interface.

I would like to first reiterate that what you choose is going to depend on your needs for a particular project. JSF and component libraries are perfect for certain situations, but may not be a good choice at all for others. If you want to have a lot of control over the JavaScript, then this is not the solution. However, in some cases, component libraries can help you get your user interface up and running both quickly and effectively.

JavaScript can be very fun to work with, especially now in the time of HTML5. I am in no way encouraging anyone to stay away (go play with the new frameworks for JavaScript and you will be saying how much fun it can be too. Really!). Nor am I pushing IceFaces as the best component library; I’m using it as an example because I was recently working on a project where it was successfully used.

Setup

If you want to use ICEFaces, then you will need to go to the website and get the appropriate download. Open the PDF guide and step through the Eclipse setup (hint: if you’ve downloaded the files, be sure to select local content when doing the Eclipse install not the archive). You will need to pick a JSF implementation to use. I recommend using STS for easier setup. You can select from several JSF implementations. Or you can download your desired implementation manually and setup the library as described in the document.

For this demo, I am using Apache MyFaces. Also note that there are lots of ways to set up a JSF project – I’m using this one for simplicity.

Component Libraries

Just a quick reminder: JSF implementations offer up the basic HTML components while component libraries add the extra stuff to make UI development quick and easy.

For this example, I am using ICEFaces ACE Components. ICEFaces offers two sets of components: ICE components and ACE components. The ICEsoft website states that ICE components are primarily geared towards legacy browser support, specialized applications and application migration. The ICEsoft website describes ACE Components (Advanced components) as “ideally suited to ICEfaces projects that are able to leverage the power of modern browsers to provide a richer, more dynamic and responsive user-interface.”

Here we will use the following ACE Components: ace:dataTable, ace:tabSet, ace:menuBar, ace:menuItem and ace:tabPane.

Examples

This example application is far from complete. I am pulling partly from the freely available ICEFaces demo application as a base and creating parts of an admin console for a silly bingo game application. I’m viewing this as the first step to an administrative page where the a user can both create a game and edit existing games.

The facelets template (template.xhtml) is set up and imported into the index page. The template defines the header, body and divs. The index then defines the ui items using ui:define. ui:define is a JSF facelets templating tag that defines named content to be inserted into a template. The name attribute value must match that of a ui:insert tag in the target template for the named content to be included.

I have created an underlying Game.java class and a MenuBarBean.java class. MenuBarBean is where the tableData list is populated. In this example, I am using static content inserted into the dataTable upon initialization for simplicity.

A Basic Menu Bar

In template.xhtml:

<div class="topMenu">
		<h:form id="form">
			<ace:menuBar id="#{menuBarBean.menuBarId}" autoSubmenuDisplay="true"
				styleClass="menuBar">
				<ui:insert name="menuItems" />
			</ace:menuBar>
		</h:form>
	</div>

In index.xhtml:

<ui:define name="menuItems">
	<ace:menuItem value="Home" url="#" icon="ui-icon ui-icon-home"
		styleClass="menuBarItem" />
		<ace:submenu label="New Game" styleClass="menuBarItem">
			<ace:menuItem value="Create From Scratch" />
			<ace:menuItem value="Use Game Template" />
		</ace:submenu>
		<ace:submenu label="Predefied Games" url="#" styleClass="menuBarItem">
			<ace:menuItem value="Crazy Holiday Bingo" />
		</ace:submenu>
	</ui:define>

I’ve used the submenu option. The urls are currently undefined, however you can see how this would be linked up.

Alright, so let’s see what this looks like. You can see the three new menu items here and the submenu items created for the New Game selection.

Next we have the dataTable. Here are the contents of the dataTable.xhtml file, which is then used in the index.xhtml. The ui:composition tag is a templating tag that wraps content to be included in another Facelet.

In dataTable.xhtml:

ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ace="http://www.icefaces.org/icefaces/components">
		<ace:dataTable rows="10" value="#{menuBarBean.tableData}" var="game"
			paginator="true" paginatorPosition="bottom">
			<ace:column id="id" headerText="Id">
				<h:outputText id="idCell" value="#{game.id}" />
			</ace:column>
			<ace:column id="gameName" headerText="Game Name">
				<h:outputText id="gameNameCell" value="#{game.gameName}" />
			</ace:column>
			<ace:column id="creator" headerText="Creator">
				<h:outputText id="creatorCell" value="#{game.creator}" />
			</ace:column>
		</ace:dataTable>
</ui:composition>

In template.xhtml:

<div class="contentBody">
	<h:form id="form2">
		<ace:tabSet>
			<ui:insert name="tabItems" />
		</ace:tabSet>
	</h:form>
</div>

In index.xhtml:

<ui:define name="tabItems">
	<ace:tabPane label="Favorites">
		<ui:include src="WEB-INF/templates/dataTable.xhtml" />
	</ace:tabPane>
	<ace:tabPane label="Still in Progress">
		<ui:include src="WEB-INF/templates/dataTable.xhtml" />
	</ace:tabPane>
</ui:define>

Here you can see the two new tabs that were created and the populated dataTable:

As you can see, we were able to quickly get important parts of our user interface up and running with some commonly-needed components.

For further information check out the following websites:

— Adrienne Gessler, asktheteam@keyholesoftware.com

  • Share:

2 Responses to “JSF Components – A Quick Example Using ICEFaces”

  1. djkieras says:

    Good intro! If you are doing any accessibility work regarding Section 508, ICEFaces actually considers those requirements and scenarios in their components as often as they can. So if you are forward-thinking and choosing a framework to support that down the road, know that there’s not just the convenience of getting up and going quickly, but some real depth to ICEFaces that will serve you well long-term.

Leave a Reply

Things Twitter is Talking About
  • Did you know? Today in 1986 it was ruled that computer code is protected under copyright law - http://t.co/mCmWPvKOBE
    September 22, 2014 at 4:30 PM
  • Don't miss Alok Pandey's very first post on the Keyhole blog - Creating a UI Designer for Quick Development http://t.co/dWYMCOO3rf
    September 22, 2014 at 2:43 PM
  • If you're a Java dev, you're likely familiar with Annotations. But have you created your own #Java Annotations? Ex - http://t.co/mf1F3eIDY3
    September 21, 2014 at 5:15 PM
  • Check out a quick intro to Functional Reactive Programing and #JavaScript - http://t.co/4LSt6aPJvG
    September 20, 2014 at 11:15 AM
  • In Part 2 of our series on creating your own #Java annotations, learn about processing them with the Reflection API - http://t.co/E1lr3RmjI7
    September 19, 2014 at 12:15 PM
  • The life of a Keyhole consultant - A Delicate Balance: It’s What We Do http://t.co/ToRpWY3aix Blog as true today as the day it was written.
    September 19, 2014 at 9:50 AM
  • 7 Things You Can Do to Become a Better Developer - http://t.co/llPNMUN8nQ
    September 19, 2014 at 8:43 AM
  • .@jessitron Good luck, you'll do great! Our team really enjoyed your KCDC14 talks.
    September 18, 2014 at 10:19 AM
  • RT @woodwardjd: 7 deadly sins of programming. I think I did all of this last week. #strangeloop http://t.co/f7QFq1SpqW
    September 18, 2014 at 10:03 AM
  • In Part 2 of our series on creating your own #Java annotations, learn about processing them with the Reflection API - http://t.co/E1lr3RmjI7
    September 17, 2014 at 3:18 PM
  • We send out our free monthly tech newsletter tomorrow - dev tips/articles via email. Not on the list? Sign up: http://t.co/h8kpjn419s
    September 16, 2014 at 2:58 PM
  • Want to chuckle? If programming languages were vehicles -http://t.co/quqHsUFCtR #funny
    September 16, 2014 at 11:41 AM
  • In Part 2 of our series on creating your own annotations, learn about processing #Java annotations using Reflection: http://t.co/DJZvQuarkc
    September 16, 2014 at 9:06 AM
  • Don't miss @jhackett01's newest post on the Keyhole blog - Processing #Java Annotations Using Reflection: http://t.co/E1lr3RmjI7
    September 15, 2014 at 12:02 PM
  • We're pretty excited - Keyhole's #BikeMS team raised 158% of their fundraising goal to benefit @MidAmericaMS. Plus, they had a great ride!
    September 15, 2014 at 10:38 AM
  • A huge welcome to David Kelly (@rheomatic) who officially joins the Keyhole team today! :-)
    September 15, 2014 at 10:00 AM
  • Sending warm thoughts to @eastlack, @cdesalvo, @wdpitt & all participating in #BikeMS this AM. Thanks for helping in the fight against MS!
    September 13, 2014 at 8:10 AM
  • .@rheomatic We are so excited to have you joining the team! Welcome :-)
    September 12, 2014 at 4:11 PM
  • As the official holiday is a Saturday, we're celebrating today! Happy (early) #ProgrammersDay to you! http://t.co/1CvUfrzytE
    September 12, 2014 at 1:55 PM
  • Tomorrow @cdesalvo, @eastlack, & @wdpitt are riding #BikeMS to benefit @MidAmericaMS. You can get involved, too - http://t.co/9boQwEUxth
    September 12, 2014 at 11:00 AM
Keyhole Software
8900 State Line Road, Suite 455
Leawood, KS 66206
ph: 877-521-7769
© 2014 Keyhole Software, LLC. All rights reserved.