Class EnumSingleSelectBoxDisplay2<E extends Enum<E>>
java.lang.Object
name.matthewgreet.strutscommons.view.EnumSingleSelectBoxDisplay2<E>
Template that aids creation of OPTION tags in JSPs for single selection SELECT elements by formatting an
enumerated type for display and selecting from a current value. Subclasses should be created in the JSP as a bean
and the selectedValue
property set with the currently selected item. See also
SelectBoxItemDisplay2
.
Example JSP code:
<SELECT SIZE="1" NAME="category" />
<s:iterator value="categoryDisplay.list" var="categoryItemDisplay">
<OPTION VALUE="<s:property value="#categoryItemDisplay.value"/>" <s:property value="#categoryItemDisplay.selectedAttribute"/>><s:property value="#categoryItemDisplay.text"/></OPTION>
</s:iterator>
</SELECT>
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts blank value to beginning of list.protected void
addItems
(List<SelectBoxItemDisplay2<E, E>> formattedModel) May be overridden by subclasses to add additional, formatted items to the display list.protected String
IfhasBlankValue()
returns true oraddBlankValue()
is called, returns text to display for blank value.protected abstract E[]
Overridden by subclass to return the values of the enumerated type.getList()
Returns formatted version of account list for human display.protected Comparator
<SelectBoxItemDisplay2<E, E>> May be overridden by subclasses to return a comparator for defining display order of formatted items.protected String
May be overridden by subclasses to return text to be displayed to user as part of OPTION element.protected String
May be overridden by subclasses to return string to be used in VALUE attribute of OPTION element.protected boolean
May be overridden by subclasses to return true, inserting a blank value at the beginning of the SELECT list.protected boolean
May be overridden by subclasses to filter items in lookup list from display.protected SelectBoxItemDisplay2
<E, E> makeSelectBoxItemDisplay
(String value, String text, E data) May be overridden by subclasses to return formatted text of an enumerated value for display in a select box.void
setList
(List<SelectBoxItemDisplay2<E, E>> value) Directly sets formatted version of account list for human display.void
setSelectedFormattedValue
(String value) Sets selected item of list identified by its value.void
setSelectedFormattedValueWithConversionError
(String value, String conversionErrorName) Selects item matching named Struts 2 conversion error (rejected form field value), or formatted identifier if conversion error not found.void
setSelectedValue
(E value) Sets selected item of list identified by its value.void
setSelectedValueWithConversionError
(E key, String conversionErrorName) Selects item matching named Struts 2 conversion error (rejected form field value), or unformatted identifier if conversion error not found.
-
Constructor Details
-
EnumSingleSelectBoxDisplay2
public EnumSingleSelectBoxDisplay2()
-
-
Method Details
-
addItems
May be overridden by subclasses to add additional, formatted items to the display list. This is typically used to add a blank item to represent no value or text that demands a real value is selected.- Parameters:
formattedModel
- List ofSelectBoxItemDisplay2
-
getBlankText
IfhasBlankValue()
returns true oraddBlankValue()
is called, returns text to display for blank value. Defaults to blank. -
getEnumValues
Overridden by subclass to return the values of the enumerated type. This function exists because the values cannot be extracted from a generic, enumerated type; -
getSortComparator
May be overridden by subclasses to return a comparator for defining display order of formatted items. Comparator compares instances ofSelectBoxItemDisplay2
that are allowed by subclass. Defaults to comparator that sorts by ascending enumeration order. -
getText
May be overridden by subclasses to return text to be displayed to user as part of OPTION element. This is typically overridden as enumeration names aren't friendly for user display. -
getValue
May be overridden by subclasses to return string to be used in VALUE attribute of OPTION element. It is rarely useful to override this. -
hasBlankValue
protected boolean hasBlankValue()May be overridden by subclasses to return true, inserting a blank value at the beginning of the SELECT list. Defaults to false. -
isAllowed
May be overridden by subclasses to filter items in lookup list from display. Defaults to allow all items. -
makeSelectBoxItemDisplay
May be overridden by subclasses to return formatted text of an enumerated value for display in a select box. data will be null for a blank entry. -
addBlankValue
public void addBlankValue()Inserts blank value to beginning of list. This is useful for search fields where a blank value means no search. -
getList
Returns formatted version of account list for human display. -
setList
Directly sets formatted version of account list for human display. The value must already be sorted. -
setSelectedFormattedValueWithConversionError
Selects item matching named Struts 2 conversion error (rejected form field value), or formatted identifier if conversion error not found. Only appropriate in a Struts 2 context.- Parameters:
value
- Formatted identifier of item..conversionErrorName
- Name of Struts 2 conversion error, which will have the "<form name>.<field name>" format.
-
setSelectedValueWithConversionError
Selects item matching named Struts 2 conversion error (rejected form field value), or unformatted identifier if conversion error not found. Only appropriate in a Struts 2 context.- Parameters:
key
- Unformatted identifier of item..conversionErrorName
- Name of Struts 2 conversion error, which will have the "<form name>.<field name>" format.
-
setSelectedFormattedValue
Sets selected item of list identified by its value.- Parameters:
value
- Formatted value of selected item or null or empty string to select none.
-
setSelectedValue
Sets selected item of list identified by its value.- Parameters:
value
- id of selected item or null to select none.
-