|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Feature Java Feature: Struts and JavaServer Faces
Design patterns for list selection
By: Heman Robinson
Mar. 24, 2006 03:00 PM
Jakarta Struts provides a standard framework for Web applications, and JavaServer Faces offers a component-based framework for user interfaces.
This article describes the following patterns:
Background 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
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() ... 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"> 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"> 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
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() ... 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"> 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"> Pattern 3: Multiple Selections from Few
As in Pattern 1, vertical alignment makes the checkboxes easier to click and the text easier to scan4. Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||