Search WebSpherePower's 6,973 WebSphere, Java, and Eclipse article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
PROGRAMMING POWER
Using a reusable code approach to HTML select option lists: part III
By Jeff Chilton

"Nothing is particularly hard if you divide it into small jobs."
-- Henry Ford (American Industrialist, 1863-1947)

We started out in Part I by creating a simple framework for the purpose of obtaining an ArrayList of Struts LabelValueBeans to support an html:options tag. In Part II, we added an additional implementing class to our portfolio, then went back and enhanced our base framework. This time, we'll reverse the order of things and first enhance our base framework, then add yet another implementing class.

Incremental Improvement #1: adding support for filtered lists
Currently, our little framework supports two kinds of lists: those with just the valid options and those with the valid options plus an additional option for leaving the field empty. In either case, the list of valid options is always the same. There are situations, however, where the available options will change based on some other event or data element.

For example, based on your security level, you may only be able to choose from four items off of a list while someone with a different security level may be authorized to select from six. In this case, the different lists of possible choices are filtered based on who you are.

To support filtered option lists, we can add two new methods to our interface that take as an argument an Object for the filter. We will need two of them to parallel the two existing methods that do not take a filter as an argument, one that includes the "required" flag and one that does not. We could have used a String for the filter, but by using an Object, we maximize the flexibility of the interface. That way certain implementations that require more than one filter String or use as a filter something other than a String can still implement the same methods. Listing 1 contains our revised interface.


package step.three;

import java.util.ArrayList;

/**
* This interface specifies the required methods for an "Option
* List" source, which returns the name/value pairs for the options
* related to an HTML "select" tag.
*/
public interface OptionListSource {

/**
* Returns a filtered array of LabelValueBean
* objects defining the available options.
*
* This method should return the same results as using the method
* getOptions(filter, true).
*
* @param filter an implementation-defined filter parameter
* further identifying or limiting the available options
* @return an ArrayList of LabelValueBean
* objects defining the available options
*/
public ArrayList getOptions(Object filter);

/**
* Returns a filtered array of LabelValueBean
* objects defining the available options.
*
* @param filter an implementation-defined filter parameter
* further identifying or limiting the available options
* @param required a boolean indicating whether or not input is
* required for this field. Setting this indicator to false will
* cause the generation of an additional option for no selection.
* @return an ArrayList of LabelValueBean
* objects defining the available options
*/
public ArrayList getOptions(Object filter, boolean required);

/**
* Returns an ArrayList of LabelValueBean
* objects defining the available options.
*
* This method should return the same results as using the method
* getOptions(true).
*
* @return an ArrayList of LabelValueBean
* objects defining the available options
*/
public ArrayList getOptions();

/**
* Returns an ArrayList of LabelValueBean
* objects defining the available options.
*
* @param required a boolean indicating whether or not input is
* required for this field. Setting this indicator to false will
* cause the generation of an additional option for no selection.
* @return an ArrayList of LabelValueBean
* objects defining the available options
*/
public ArrayList getOptions(boolean required);
}


1  ·  2  ·  3  ·  4  ·  Next »
Other articles you might like
Home > Projects > Reusable Code (5 articles)
   Using a reusable code approach to HTML select option lists, part VI
   Using a reusable code approach to HTML select option lists, part V
   Using a reusable code approach to HTML select option lists, part IV
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent WebSpherePower Articles
A perfect 10: celebrating 10 years online
You can help bring security and safety back to White House email
Introducing the WebSpherePower RSS feeds
From New Jersey to Palm Bay, Florida
A WebSphere pot o' gold
How Elvis entered the building and CES went out the window
WebSphere Application Server 6: what's it all mean?
WebSpherePower News
Legal question: Can HP keep Hurd from going to Oracle?
Caringo announces integration with Symantec EV 9.0
Cisco & Citrix marry on virty PCs
Take Heed, Tech Giants: Edison's Failed Plot To Hijack Hollywood
IBM code unchains virtual workloads
Oracle names H-P ex-CEO Mark Hurd as co-president
Cloud Messaging Provider, Linxter, Releases SDK for Java and Android
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Introducing the Jones family and their full-family backup challenges
David Gewirtz Online: CNN commentary and analysis
DominoPower: Lotus must open source Notes and Domino
OutlookPower: Hands on debugging a broken Outlook forwarding rule
-- Advertisement --

EASY DEDICATED AND VIRTUAL DEDICATED SERVERS FOR AS LOW AS $67.99 PER MONTH
Customize and configure your own dedicated server. Simply choose one of our popular plans or select your own Linux or Windows server and plan options.

NO LONG WAITS. Server provisioned within hours.

Tap here now and be up and running with your own server tonight.

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login