Search WebSpherePower's 6,962 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
Excitement brewing for JavaOne 2010, with or without Google
Large companies ignore data centre advice
Onapsis to Release ERP Vulnerability Testing Suite
Botnet Takedown May Yield Valuable Data
VMware app dev platform gazes beyond SpringSource Java
IBM Claims World's Fastest Chip
'Free Java': InfoWorld's guide to the protest goodies
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Smartphone smarts for a mobile world
David Gewirtz Online: CNN commentary and analysis
DominoPower: It's time for Lotus to double-down on Linux and open source
OutlookPower: The strange case of Outlook losing notes and requiring passwords
-- Advertisement --

How To Save Jobs
This book is about how to create and save jobs. Believe it or not, there's not a single book out there that specifically focuses on job creation and preservation -- until now.

This book, by ZATZ editor-in-chief David Gewirtz, is about helping your business work better. It's about helping you change the things you need to change so your company can perform more effectively.

Plus, through a grant from ZATZ, it's a free download.

Read it and reap.

-- Advertisement --

Influencer. Recommender. Decision Maker.
They all read WebSpherePower Magazine. They all rely on WebSpherePower Magazine.

If you want to reach the inner-circle of IBM IT professionals, you won't find a better resource than WebSpherePower Magazine.

Click for our Media Kit

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