Class EnumSingleSelectBoxDisplay2<E extends Enum<E>>

java.lang.Object
name.matthewgreet.strutscommons.view.EnumSingleSelectBoxDisplay2<E>

public abstract class EnumSingleSelectBoxDisplay2<E extends Enum<E>> extends Object

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 selectedValueproperty 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>

  • Constructor Details

    • EnumSingleSelectBoxDisplay2

      public EnumSingleSelectBoxDisplay2()
  • Method Details

    • addItems

      protected void addItems(List<SelectBoxItemDisplay2<E,E>> 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.
      Parameters:
      formattedModel - List of SelectBoxItemDisplay2
    • getBlankText

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

      protected abstract E[] 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

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

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

      protected String getValue(E item)
      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

      protected boolean isAllowed(E item)
      May be overridden by subclasses to filter items in lookup list from display. Defaults to allow all items.
    • makeSelectBoxItemDisplay

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

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

      public void setList(List<SelectBoxItemDisplay2<E,E>> value)
      Directly sets formatted version of account list for human display. The value must already be sorted.
    • 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(E 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)
      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

      public void setSelectedValue(E value)
      Sets selected item of list identified by its value.
      Parameters:
      value - id of selected item or null to select none.