com.primix.tapestry.form
Class EnumPropertySelectionModel

java.lang.Object
  |
  +--com.primix.tapestry.form.EnumPropertySelectionModel
All Implemented Interfaces:
IPropertySelectionModel

public class EnumPropertySelectionModel
extends java.lang.Object
implements IPropertySelectionModel

Implementation of IPropertySelectionModel that wraps around a set of Enums. In addition to this, a Locale and some information needed to extract labels from a ResourceBundle are provided.

Uses a simple index number as the value (used to represent the option).

The resource bundle from which labels are extracted is usually a resource within the Tapestry application. Since ResourceBundle.getBundle(String, Locale) uses its caller's class loader, and that classloader will be the Tapestry framework's classloader, the application's resources won't be visible. This requires that the application resolve the resource to a ResourceBundle before creating this model.

Version:
$Id: EnumPropertySelectionModel.java,v 1.3 2001/05/02 14:15:16 hship Exp $
Author:
Howard Ship

Constructor Summary
EnumPropertySelectionModel(Enum[] options, java.util.ResourceBundle bundle)
          Simplified constructor using the default locale and no prefix.
EnumPropertySelectionModel(Enum[] options, java.util.ResourceBundle bundle, java.lang.String resourcePrefix)
          Standard constructor.
 
Method Summary
 java.lang.String getLabel(int index)
          Returns the label for an option.
 java.lang.Object getOption(int index)
          Returns one possible option.
 int getOptionCount()
          Returns the number of possible options.
 java.lang.String getValue(int index)
          Returns a String used to represent the option in the HTML (as the value of an <option> or <input type=radio>.
 java.lang.Object translateValue(java.lang.String value)
          Returns the option corresponding to a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumPropertySelectionModel

public EnumPropertySelectionModel(Enum[] options,
                                  java.util.ResourceBundle bundle,
                                  java.lang.String resourcePrefix)
Standard constructor.

Labels for the options are extracted from a resource bundle. resourceBaseName identifies the bundle. Typically, the bundle will be a .properties file within the classpath. Specify the fully qualified class name equivalent, i.e., for file /com/example/foo/LabelStrings.properties use com.example.foo.LabelStrings as the resource base name.

Normally (when resourcePrefix is null), the keys used to extract labels matches the enumeration id of the option. By convention, the enumeration id matches the name of the static variable.

To avoid naming conflicts when using a single resource bundle for multiple models, use a resource prefix. This is a string which is prepended to the enumeration id (they prefix and enumeration id are seperated with a period).

Parameters:
options - The list of possible values for this model, in the order they should appear. This exact array is retained (not copied).
locale - The Locale for which labels should be generated.
bundle - The ResourceBundle from which labels may be extracted.
resourcePrefix - An optional prefix used when accessing keys within the bundle.

EnumPropertySelectionModel

public EnumPropertySelectionModel(Enum[] options,
                                  java.util.ResourceBundle bundle)
Simplified constructor using the default locale and no prefix.
Method Detail

getOptionCount

public int getOptionCount()
Description copied from interface: IPropertySelectionModel
Returns the number of possible options.
Specified by:
getOptionCount in interface IPropertySelectionModel

getOption

public java.lang.Object getOption(int index)
Description copied from interface: IPropertySelectionModel
Returns one possible option.
Specified by:
getOption in interface IPropertySelectionModel

getLabel

public java.lang.String getLabel(int index)
Description copied from interface: IPropertySelectionModel
Returns the label for an option. It is the responsibility of the adaptor to make this value localized.
Specified by:
getLabel in interface IPropertySelectionModel

getValue

public java.lang.String getValue(int index)
Description copied from interface: IPropertySelectionModel
Returns a String used to represent the option in the HTML (as the value of an <option> or <input type=radio>.
Specified by:
getValue in interface IPropertySelectionModel

translateValue

public java.lang.Object translateValue(java.lang.String value)
Description copied from interface: IPropertySelectionModel
Returns the option corresponding to a value. This is used when interpreting submitted form parameters.
Specified by:
translateValue in interface IPropertySelectionModel