Class SingleSelectBoxDisplay2<K,T>

java.lang.Object
name.matthewgreet.strutscommons.view.SingleSelectBoxDisplay2<K,T>
Direct Known Subclasses:
IntegerListSelectBoxDisplay2

public abstract class SingleSelectBoxDisplay2<K,T> extends Object
Template that aids creation of OPTION tags in JSPs for single selection SELECT elements by formatting an unformatted list for display. Concrete subclasses override getKey(T), getValue(K) and getText(T) to extract record ids, OPTION tag values and display text from an unformatted list. 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>

  • Constructor Details

    • SingleSelectBoxDisplay2

      public SingleSelectBoxDisplay2()
  • Method Details

    • addItems

      protected void addItems(List<SelectBoxItemDisplay2<K,T>> formattedModel)
      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 of SelectBoxItemDisplay
    • getBlankText

      protected String getBlankText()
      If hasBlankValue() returns true or addBlankValue() is called, returns text to display for blank value. Defaults to blank.
    • getInitialList

      protected List<SelectBoxItemDisplay2<K,T>> 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

      protected abstract K getKey(T item)
      Overridden by subclasses to return unformatted identifier of item record. This is the value used to match the parameter of setSelectedValue(K).
      Parameters:
      item - Member of raw data list to be displayed.
    • getLogger

      protected org.apache.logging.log4j.Logger getLogger()
      May be overridden by subclasses to return logger of subclass.
    • getSortComparator

      protected Comparator<SelectBoxItemDisplay2<K,T>> getSortComparator()
      May be overridden by subclasses to return a comparator for defining display order of formatted items. Comparator compares instances of SelectBoxItemDisplay that are allowed by subclass. Defaults to comparator that sorts by ascending display text.
    • getText

      protected abstract String getText(T item)
      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

      protected abstract String getValue(K key)
      Overridden by subclasses to return string to be used in VALUE attribute of OPTION element. This is the formatted version of the item record identifier and is the value used to match the parameter of setSelectedFormattedValue(java.lang.String).
      Parameters:
      key - Identifier of unformatted record.
    • 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

      protected boolean isAllowed(T item)
      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.
    • addBlankValue

      public void addBlankValue()
      If called after setModel(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

      public List<SelectBoxItemDisplay2<K,T>> getList()
      Returns formatted version of account list for human display.
    • getSelectedItem

      public SelectBoxItemDisplay2<K,T> getSelectedItem()
      Returns selected, formatted item or null if none selected.
    • setList

      public void setList(List<SelectBoxItemDisplay2<K,T>> value)
      Directly sets formatted list. The value must already be sorted.
    • setModel

      public void setModel(Collection<T> model)
      Sets unformatted values and creates formatted, sorted list from it.
    • setSelectedFormattedValueWithConversionError

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

      public void setSelectedValueWithConversionError(K key, String conversionErrorName)
      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

      public void setSelectedFormattedValue(String value)
      Selects item matching formatted identifier. This matches the OPTION tag VALUE attribute.
      Parameters:
      value - Formatted identifier of selected item or null or empty string to select none.
    • setSelectedValue

      public void setSelectedValue(K key)
      Selects item matching unformatted identifier. Formatted version of key matches the OPTION tag VALUE attribute.
      Parameters:
      key - id of selected item or null to select none.