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
  • @rickincanada Thx for your tweet! Shoot us an email at asktheteam@keyholesoftware.com so we can set up a time to talk. Have a good day.
    July 24, 2014 at 3:33 PM
  • Never used JAXB? Check out a simple usage pattern that pairs #JAXB’s data binding capabilities with JPA - http://t.co/Ki9G04HV5e
    July 24, 2014 at 9:53 AM
  • Guess what today is? Tell An Old Joke Day - http://t.co/835ORWMX6N! So, why do programmers always confuse Halloween & Xmas? 31 Oct = 25 Dec
    July 24, 2014 at 8:45 AM
  • MT @midwestio: Posted another #midwestio talk recording to our YouTube channel: @MinaMarkham on modular CSS. Watch: http://t.co/aU3LpfUoi4
    July 24, 2014 at 8:25 AM
  • We just posted pictures from our National Hot Dog Day Lunch Cookout. Check them out - http://t.co/To06plaw1C
    July 23, 2014 at 4:14 PM
  • Good free cheat sheet - #Java Performance Optimization Refcard from @DZone: http://t.co/7vBgsmqy08
    July 23, 2014 at 10:48 AM
  • Did you know today is a holiday? It's National Hot Dog Day! We're gearing up for our team lunch hot dog cookout & can't wait to celebrate.
    July 23, 2014 at 9:43 AM
  • Check out our newest blog: #JAXB – A Newcomer’s Perspective, Part 1 http://t.co/Ki9G04HV5e
    July 22, 2014 at 1:22 PM
  • New post on the Keyhole blog by Mark Adelsberger: #JAXB – A Newcomer’s Perspective, Part 1 http://t.co/Ki9G04HV5e
    July 21, 2014 at 2:27 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/BgCsYjxZKF
    July 18, 2014 at 12:10 PM
  • RT @gamasutra: Don't Miss: Unconventional Tips for Improving your Programming Skills http://t.co/6TFox7CKHU
    July 16, 2014 at 3:20 PM
  • We're about to send out our free monthly tech newsletter. Dev tips/articles via email. Not on the list yet? Sign up - http://t.co/F8h0NSiicZ
    July 15, 2014 at 11:57 AM
  • Have you ever tried creating your own #Java annotations? See a situation where it was beneficial - http://t.co/BgCsYjxZKF
    July 15, 2014 at 8:36 AM
  • There's a new post on the Keyhole blog by @jhackett01: Creating Your Own #Java Annotations - http://t.co/BgCsYjxZKF
    July 14, 2014 at 1:43 PM
  • We love development! Have you seen our weekly team blog? We show how to be successful with the tech we use. See it - http://t.co/nlRtb1XNQH
    July 12, 2014 at 2:35 PM
  • Rapid appdev has a bad rep, but there are ways to bring development time down the right way. Don't Fear the Rapid - http://t.co/aTPcAKOj0r
    July 11, 2014 at 3:10 PM
  • Automated Testing is great for dev, but does bring a set of challenges (especially for #agile teams). Success tips: http://t.co/1acl1ngO7i
    July 11, 2014 at 12:16 PM
  • This is fantastic - One small step for Google, one giant leap for empowering girls to code: http://t.co/R90V5DBkv1
    July 10, 2014 at 2:52 PM
  • #RabbitMQ: messaging software built on AMQP protocol. Learn relevant concepts & how to avoid common "gotchas" here: http://t.co/ZwMXlhKyX8
    July 10, 2014 at 9:31 AM
  • A huge welcome to Brian Wetzel who joins the Keyhole team today!
    July 10, 2014 at 8:50 AM
Keyhole Software
8900 State Line Road, Suite 455
Leawood, KS 66206
ph: 877-521-7769
© 2014 Keyhole Software, LLC. All rights reserved.