Email:   
Home
In This Issue
EasyPrint
Click here for the RSS feed's XML code. This is not a browser URL.
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;
}
}




[ Prev | Next ]

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
-- 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.

-- 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

Copyright © 2008, ZATZ Publishing. All rights reserved worldwide.
Editor's Login