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.
Using a reusable code approach to HTML select option lists: part II (continued)

Listing 4 contains the associated abstract base class with the new functionality.

package step.two;

import java.util.ArrayList;

import org.apache.struts.util.LabelValueBean;

/**
* 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;
private ArrayList optionsPlusBlank = null;

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

/**
* Returns an <code>ArrayList</code> of <code>LabelValueBean</code>
* 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 <code>ArrayList</code> of <code>LabelValueBean</code>
* objects defining the available options
*/
public ArrayList getOptions(boolean required) {
if (options == null) {
loadOptionsArrays();
}

if (required) {
return options;
} else {
return optionsPlusBlank;
}
}

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

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

optionsPlusBlank = new ArrayList();
LabelValueBean blankOption = new LabelValueBean("-- No Selection --", "");
optionsPlusBlank.add(blankOption);
optionsPlusBlank.add(options);
}

/**
* 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  ·  5  ·  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.

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