Class EnumSingleSelectBoxDisplay<E extends Enum<E>>

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

public abstract class EnumSingleSelectBoxDisplay<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 SelectBoxItemDisplay.

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

    • EnumSingleSelectBoxDisplay

      public EnumSingleSelectBoxDisplay()
  • Method Details

    • addItems

      protected void addItems(List<SelectBoxItemDisplay<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 SelectBoxItemDisplay
    • 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<SelectBoxItemDisplay<E>> 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 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 SelectBoxItemDisplay<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<SelectBoxItemDisplay<E>> getList()
      Returns formatted version of account list for human display.
    • setList

      public void setList(List<SelectBoxItemDisplay<E>> value)
      Directly sets formatted version of account list for human display. The value must already be sorted.
    • setSelectedValue

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