Search DominoPower's 11,416 Lotus-related 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.
Using a reusable code approach to HTML select option lists (continued)


package step.one;

import java.util.ArrayList;

/**
* <p>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.</p>
*/
public interface OptionListSource {

/**
* Returns an <code>ArrayList</code> of <code>LabelValueBean</code>
* objects defining the available options.
*
* @return an <code>ArrayList</code> of <code>LabelValueBean</code>
* objects defining the available options
*/
public ArrayList getOptions();
}

Create an Abstract class for the common code
One of the nicest features of Java is its support of inheritance. When you want to create a collection of similar-but-different objects for any purpose, you can consolidate all of the "similar" into a base abstract class and then implement the "different" in any number of extensions of that class. Our base class will implement our interface and provide as much of the common logic as possible without attempting to implement any of the potential optional approaches. Our abstract class is presented in Listing 2:


package step.one;

import java.util.ArrayList;

/**
* This absract class implements the required methods for an "Option
* List" source, which returns the name/value pairs for the options
* related to an HTML "select" tag.
*
* This class must be extended by a concrete subclass which must
* implement the specified abstract method <code>loadOptions()</code>
* to load the list of available options from the implementation-specific
* data source.
*/
public abstract class OptionListSourceBase implements OptionListSource {
private ArrayList options = null;

/**
* Returns an <code>ArrayList</code> of <code>LabelValueBean</code>
* objects defining the available options.
*
* @return an <code>ArrayList</code> of <code>LabelValueBean</code>
* objects defining the available options
*/
public ArrayList getOptions() {
if (options == null) {
loadOptionsArray();
}

return options;
}

/**
* Obtains the available options from the implementation-specific
* load method.
*/
protected void loadOptionsArray() {
loadOptions();

if (options == null) {
options = new ArrayList();
System.out.println(this.getClass().getName() + ".loadOptions() produced no result.");
}
}

/**
* Loads the list of available options from the implementation-specific
* data source.
*/
protected abstract void loadOptions();

/**
* Sets the <code>ArrayList</code> of <code>LabelValueBean</code>
* objects defining the available options.
*
* @param options the <code>ArrayList</code> of <code>LabelValueBean</code>
* objects defining the available options
*/
protected void setOptions(ArrayList options) {
this.options = options;
}
}


« Previous  ·  1  ·  2  ·  3  ·  4  ·  Next »
Other articles you might like
Home > Internet Technologies > HTML and CSS (15 articles)
   One reader's opinion on HTML mailing
   Keep lookin' good with Cascading Style Sheets
   Cascading Style Sheets make you look good
Home > Internet Technologies > Java (6 articles)
   FlowBuilder 3.0: Domino's bridge into J2EE
   Post-Lotusphere 2004 report: gaining understanding and perspective
   Survey reveals trends in Java use on Domino
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Five trends for 2010
Latest Lotus Headlines
More XPages onclick event weirdness...
Domino 8.5.1 Fix Pack 1 Interim Fix 1 (8.5.1 FP1 IF1) - DAOS Fixes
Domino Designer 8.5 Tip: Where Working Sets Are Stored
Invitation: LTIE Community Meeting - Tuesday, March 23rd 10AM ET
Flex: Using A SharedObject to Remember User Settings
Copy file instead of a link with Quickr connector in Notes
EclipseSource to Participate in Eclipse Foundation's Eclipse Training Series
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Make Mafia Wars an offer it can't refuse
David Gewirtz Online: CNN commentary and analysis
OutlookPower: Removing an Office installation that doesn't want to go away
-- Advertisement --

Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.

The many included activities and demos will make you a pro! Expert instructor help is a click away.

Click here to try a FREE demo course!!

-- Advertisement --

Teamstudio Edition 25 has shipped
It's finally here! Now that Teamstudio Edition 25 has shipped, listen to our latest Tool Time audio program to find out what's changed. Updates to all your favorite Teamstudio tools will be discussed.

Plus, you'll get an introduction to Teamstudio Undo (formerly known as Teamstudio Snapper).

Tap here to get started!

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