Search WebSpherePower's 5,995 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
All SaaS-Ed Up
WebSphere Application Server V7.0 Security Guide
PostgreSQL 8.4 Released, Now Easier to Use Than Ever
Sun's VirtualBox 3.0 exits betaland
Capitalware releases MQ Channel Monitor v1.0.0 for Free
OpsWise Software Announces Workload Automation Broker for Cloud Computing
O'Reilly Webcast: Cloud Computing: The Next Frontier for Open Source
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Eight steps to successful and reliable home backups
David Gewirtz Online: CNN commentary and analysis
DominoPower: What to look for in a Domino-based document management solution
OutlookPower: Can Outlook run when it's not running (and other mysteries)?
-- Advertisement --

SECURE YOUR SITE WITH AN IRONCLAD SSL CERTIFICATE
An IronClad SSL Certificate helps you build an impenetrable fortress around your customer's credit card information. IronClad SSL Certificates are:

  • Fully validated
  • Up to 256-bit encryption
  • One, two, or three year validity (our Turbo SSL Certificates are valid up to 10 years)
  • 99% browser recognition
  • Stringent authentication
  • Around-the-clock customer support

Build trust. Protect your customers. Grow your online business.

Tap here now and be IronClad with SSL tonight.

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 2009, ZATZ Publishing. All rights reserved worldwide.