|
|
|
|
|
|
|
|
|
|
|
|
|
|
Using a reusable code approach to HTML select option lists: part III (continued)
Listing 2 contains the associated abstract base class that implements this new interface.
package step.three;
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 loadOptions()
* 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 a filtered array of LabelValueBean
* objects defining the available options.
*
* This method will 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) {
return getOptions(filter, true);
}
/**
* Returns a filtered array of LabelValueBean
* objects defining the available options.
*
* The default implementation of this method ignores the
* filter and invokes the unfiltered getOptions()
* method. Implementations that require filtered options should
* override this method with the appropriate implementation-
* specific code.
*
* @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) {
return getOptions(required);
}
/**
* Returns an ArrayList of LabelValueBean
* objects defining the available options.
*
* This method will return the same results as using the method
* getOptions(true).
*
* @return an ArrayList of LabelValueBean
* objects defining the available options
*/
public ArrayList getOptions() {
return getOptions(true);
}
/**
* 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) {
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 ArrayList of LabelValueBean
* objects defining the available options.
*
* @param options the ArrayList of LabelValueBean
* objects defining the available options
*/
protected void setOptions(ArrayList options) {
this.options = options;
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- 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. |
|
|
|
|
|
|
|
|
|
|
|