Class GroupedSingleSelectBoxDisplay<K,T,G>
java.lang.Object
name.matthewgreet.strutscommons.view.GroupedSingleSelectBoxDisplay<K,T,G>
- Type Parameters:
K- Type of unique identifier of T.T- Record type of list used to generate dropdown.G- Type of describing group of T, which can be String.
Template that aids creation of OPTION and OPTGROUP tags in JSPs for single selection SELECT elements by formatting
list for display. Concrete subclasses override
getValue(T) and getText(T) to extract item values and
display text from a raw list. See also SelectBoxGroupDisplay and SelectBoxItemDisplay2.
Example JSP code:
<SELECT SIZE="1" NAME="category" >
<s:iterator value="categoryDisplay.list" var="categoryGroupDisplay">
<OPTGROUP LABEL="<s:property value="#categoryGroupDisplay.text"/>">
<s:iterator value="#categoryGroupDisplay.children" var="categoryItemDisplay">
<OPTION VALUE="<s:property value="#categoryItemDisplay.value"/>" <s:property value="#categoryItemDisplay.selectedAttribute"/>><s:property value="#categoryItemDisplay.text"/></OPTION>
</s:iterator>
</OPTGROUP>
</s:iterator>
</SELECT>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidIf called aftersetModel(java.util.Collection<T>), inserts blank value to beginning of list.protected voidMay be overridden by subclasses to add additional, formatted items to the display list.protected StringIfhasBlankValue()returns true oraddBlankValue()is called, returns text to display for blank value.protected abstract GOverridden by subclasses to return item's group.protected abstract StringgetGroupLabel(G group) Overridden by subclass to return label for a group, which becomes the LABEL attribute for OPTGROUP tags.protected Comparator<SelectBoxGroupDisplay<K, T, G>> May be overridden by subclasses to return a comparator that defines display order of groups.protected List<SelectBoxGroupDisplay<K, T, G>> May be overridden by subclasses to return initial selection, especially if the list is hardcoded and setModel will not be used.abstract KOverridden by subclasses to return unformatted identifier of item record.getList()Returns formatted version of account list for human display.Returns selected, formatted item or null if none selected.protected Comparator<SelectBoxItemDisplay2<K, T>> May be overridden by subclasses to return a comparator for defining display order of formatted items.protected abstract StringOverridden by subclasses to return formatted text to be displayed to user as part of OPTION element.protected abstract StringOverridden by subclasses to return string to be used in VALUE attribute of OPTION element.protected booleanMay be overridden by subclasses to return true, inserting a blank value at the beginning of the SELECT list.protected booleanMay be overridden by subclasses to filter items in lookup list from display.protected SelectBoxItemDisplay2<K, T> makeSelectBoxItemDisplay(String value, String text, K key, T data) May be overridden by subclasses to return formatted text of an enumerated value for display in a select box.voidDirectly sets formatted version of account list for human display.voidsetModel(Collection<T> model) Formats lookup list for use in single selection HTML SELECT element.voidsetSelectedFormattedValue(String value) Sets selected item of list identified by its value.voidsetSelectedFormattedValueWithConversionError(String value, String conversionErrorName) Selects item matching named Struts 2 conversion error (rejected form field value), or formatted identifier if conversion error not found.voidsetSelectedValue(K key) Sets selected item of list identified by its value.voidsetSelectedValueWithConversionError(K 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
-
GroupedSingleSelectBoxDisplay
public GroupedSingleSelectBoxDisplay()
-
-
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. This is called after sorting.- Parameters:
formattedModel- List ofSelectBoxGroupDisplaycontaining childSelectBoxItemDisplay.
-
getBlankText
IfhasBlankValue()returns true oraddBlankValue()is called, returns text to display for blank value. Defaults to blank. -
getGroup
Overridden by subclasses to return item's group. -
getGroupLabel
Overridden by subclass to return label for a group, which becomes the LABEL attribute for OPTGROUP tags. -
getGroupSortComparator
May be overridden by subclasses to return a comparator that defines display order of groups. Defaults to comparator that sorts by ascending display text. -
getInitialList
May be overridden by subclasses to return initial selection, especially if the list is hardcoded and setModel will not be used. Can return null for no initial list. -
getKey
Overridden by subclasses to return unformatted identifier of item record. This is the value used to match the parameter ofsetSelectedValue(K).- Parameters:
item- Member of raw data list to be displayed.
-
getSortComparator
May be overridden by subclasses to return a comparator for defining display order of formatted items. Comparator compares instances ofSelectBoxItemDisplaythat are allowed by subclass. Defaults to comparator that sorts by ascending display text. -
getText
Overridden by subclasses to return formatted text to be displayed to user as part of OPTION element.- Parameters:
item- Member of raw data list to be displayed.
-
getValue
Overridden by subclasses to return string to be used in VALUE attribute of OPTION element. This is the value return in form data.- Parameters:
item- Member of raw data list to be displayed.
-
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.- Parameters:
item- Member of raw data list to be displayed.
-
makeSelectBoxItemDisplay
protected SelectBoxItemDisplay2<K,T> makeSelectBoxItemDisplay(String value, String text, K key, T data) 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()If called aftersetModel(java.util.Collection<T>), 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. -
getSelectedItem
Returns selected, formatted item or null if none selected. -
setList
Directly sets formatted version of account list for human display. The value must already be sorted. -
setModel
Formats lookup list for use in single selection HTML SELECT element. This replaces any initial list. -
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- id of selected item or null or empty string to select none.
-
setSelectedValue
Sets selected item of list identified by its value.- Parameters:
key- unformatted id of selected item or null to select none.
-