Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Java Feature: Struts and JavaServer Faces
Design patterns for list selection

Jakarta Struts provides a standard framework for Web applications, and JavaServer Faces offers a component-based framework for user interfaces.

At the user interface, a common task in both frameworks is selecting items from lists. Over the years, standard design patterns have been developed for selection lists. For developers, the advantage of implementing these standard patterns is that they are readily available and offer a familiar user experience.

This article describes the following patterns:

  • One selection from few
  • One selection from many
  • Multiple selections from few
  • Extended selections from many
  • Multiple selections from many
These are small idioms for simple UI controls, but it's not always obvious how to implement them to maximize usability. This article describes best practices recommended by usability experts for these patterns and compares their implementations in Struts and JavaServer Faces.

Background
Both Struts and JSF architectures are based on the Model-View-Controller design pattern. This article focuses on the View, implemented using JavaServer Pages. JSPs are typical in Struts architectures3. They're not required by JavaServer Faces, but are used here for ease of comparison.

In both frameworks, JSPs are backed by JavaBeans, for which the interfaces are nearly identical in Struts and JSF. In the Struts bean, List properties are stored as LabelValueBeans; in the JSF bean they are SelectItems. Both JavaBeans are initialized in their constructors, again for ease of comparison.

JavaBean interfaces and JSP comparisons are shown in this article. JavaBean variables and constructors are shown in Listings 1 and 2. Complete JSPs are in Listings 3 and 4. The patterns that follow show controls that might be used in a Web search application.

Pattern 1: One Selection from Few
Use when:

  • One selection is needed.
  • There is room to display all available items.
The best design pattern for one selection from few items is a list of radio buttons, also known as option buttons. This pattern shows all available items and the selection requires only one mouse-click.

As pointed out in GUI Design Essentials4, vertical alignment makes the text easier to scan. This also makes the radio buttons easier to click, as it places them all in the same area. It's not always possible to align buttons vertically, but if you can, it's a service to your users.

Radio buttons are mutually exclusive, so one button should be selected by default5, 6. This costs your users nothing and may save them a step (Figure 1).

The Windows Interface Guidelines for Software Design recommends this pattern for lists with seven items or fewer7. If you have more, or screen real estate is limited, consider Pattern 2.

In the JavaBean, the "forList" property stores the list of available values. The "forValue" property stores the selected value as a string.

public List getForList() ...
public void setForList( List list ) ...
public String getForValue() ...
public void setForValue( String id ) ...

In the Struts JSP, the <logic:iterate> tag loops over the buttons specified by <html:radio> and <bean:write> tags. The "Search For:" label is provided by the <fmt:message> tag from the JSP Standard Tag Library8. Struts tags and JSTL tags are often used in combination.

<tr valign="top">
   <td align="right">
     <fmt:message key="searchFor"/>
   </td>
   <td>
     <logic:iterate name="exampleForm" property="forList" id="item">
     <html:radio property="forValue" idName="item" value="value">
 <bean:write name="item" property="label"/><br />
     </html:radio>
    </logic:iterate>
   </td>
</tr>

In the JavaServer Faces JSP, the <h:selectOneRadio> tag loops over the list specified by the <f:selectItems> tag. The "Search For:" label is provided by the <h:outputText> tag.

<h:panelGrid columns="2">
   <h:outputText value="#{bundle.searchFor}" />
   <h:selectOneRadio value="#{example.forValue}"
      layout="pageDirection" id="for">
      <f:selectItems value="#{example.forList}"/>
   </h:selectOneRadio>
</h:panelGrid>

In the JavaServer Faces JSP, code size is reduced by using more compact tags for both controls and layout. The layout tags <tr> and <td> are replaced by <h:panelGrid>. For brevity, layout and label tags are omitted in succeeding patterns.

Pattern 2: One Selection from Many
Use when:

  • One selection is needed.
  • There is not enough room to display all available items.
The standard pattern for one selection from many items is the listbox (Figure 2). A disadvantage of this pattern is that not all available items are visible. An advantage is that it requires only a small amount of space9.

This control can display several items or one. When several items are displayed, GUI Design Essentials recommends a minimum of three items and a maximum of eight.

When only one item is displayed, the control appears as a dropdown menu. The drop-down variant conserves more space but requires more user interaction7 (Figure 3).

In the JavaBean, the "updateList" property stores the list of available values. The "updateValue" property stores the selected value as a string.

public List getUpdateList() ...
public void setUpdateList( List list ) ...
public String getUpdateValue() ...
public void setUpdateValue( String id ) ...

In the Struts JSP, the <html:select> tag creates this control. The <html:optionsCollection> specifies the list. The "size" attribute of the <html:select> tag controls the number of items displayed. If "size" is omitted, it defaults to 1, which makes this control a dropdown menu.

<html:select property="updateValue" size="4">
     <html:optionsCollection property="updateList"/>
</html:select>

In JavaServer Faces, the JSP is similar to that of Pattern 1. The <h:selectOneListbox> tag loops over the list specified by the <f:selectItems> tag. The "size" attribute of the <h:selectOneListbox> tag works similarly to that of the Struts tag. If size=1, the <h:selectOneListbox> tag renders the same dropdown menu as the <h:selectOneMenu> tag, which is clearer.

<h:selectOneListbox value="#{example.updateValue}" size="4" id="update">
     <f:selectItems value="#{example.updateList}"/>
</h:selectOneListbox>

Pattern 3: Multiple Selections from Few
Use when:

  • Multiple selections are needed.
  • There is room to display all available items.
The standard pattern for multiple selections from few items is a list of check boxes. This pattern shows all the items and requires only one mouse-click per selection (Figure 4).

As in Pattern 1, vertical alignment makes the checkboxes easier to click and the text easier to scan4.

About Heman Robinson
Heman Robinson is a senior developer with SAS Institute in Cary, N.C. He holds a BS in mathematics from the University of North Carolina and an MS in computer science from the University of Southern California. He has specialized in GUI design and development for 15 years and has been a Java developer since 1996.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
Swisscom, the Swiss telecom, is going into the cloud business. Its subsidiary Swisscom IT Services AG has signed up with Red Hat as a Certified Cloud Provider and launched a public cloud Infrastructure-as-a-Service (IaaS) cloud targeting enterprise-class customers primarily in ...
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP)....
In a surprise move on Tuesday, January 10, Oracle wheeled out its Big Data Appliance. That’s the one it said in October would be ready sometime in the first half. Only nobody believed it meant early in the first half. Heck, it’s not even clear anybody thought Oracle could make ...
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
CloudLinux, Inc., on Thursday released CafeFS 3, a virtualized file system for shared hosters that cages each customer within its own virtualized file system. CageFS becomes part of CloudLinux OS at no additional charge. CloudLinux OS, the only commercially-supported Linux OS m...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News
Atlantis Computing™, the leader in Virtual Desktop Infrastructure (VDI) storage and performance opti...