Class AbstractViewListActionSupport<M extends Serializable,K extends Serializable,T extends Serializable,FT>

java.lang.Object
org.apache.struts2.ActionSupport
com.opensymphony.xwork2.ActionSupport
All Implemented Interfaces:
com.opensymphony.xwork2.Action, com.opensymphony.xwork2.interceptor.ValidationAware, com.opensymphony.xwork2.LocaleProvider, com.opensymphony.xwork2.TextProvider, com.opensymphony.xwork2.Validateable, Serializable, BrowserTabAware, BrowserTabAware2, org.apache.struts2.action.Action, org.apache.struts2.action.ServletRequestAware, org.apache.struts2.interceptor.ValidationAware, org.apache.struts2.Validateable

public abstract class AbstractViewListActionSupport<M extends Serializable,K extends Serializable,T extends Serializable,FT> extends AbstractViewActionSupport

Struts 2 Template class for displaying and controlling list data on a JSP from an instance of ListCache, which, if it's a slave list, is linked to a master list. The implementing subclass typically displays the whole list or a page of it, or displays the currently selected record of the list. URL parameters can control the list, such as selecting a different item or making the list re-find its contents according to its current search criteria. Also collects popup requests and messages made by previous actions and security data.

Concrete subclasses must implement various template functions:-

formatRecord(M, T)
Returns formatted record for display, derived from record from list.
getListCache()
Returns list cache that is being displayed.
getMasterListCache()
If the list cache is a slave list, returns master list cache that controls it, otherwise returns null.
getViewListConfig()
Returns other configuration, such as use of page mode

Concrete subclasses may implement other template functions:-

endRecordFormatting()
Cleanup after formatRecord(M, T).
getAlternateIndex(name.matthewgreet.strutscommons.util.ListCache<M, K, T>)
Returns index of list cache item to select (including -1 to select none of them) usually according to a request parameter, or null to ignore this.
getItemSorter(java.lang.String, java.lang.Boolean)
Returns a comparator for sorting the list cache, if requested. Sorting is only allowed if list cache uses full list pagination.
getViewResponse(M, T)
Loads any additional data and view helpers, such as list of countries, needed by JSP and returns Struts result, usually "success".
startRecordFormatting()
Preparation for formatRecord(M, T).

The URL parameters, whose names can be changed by config, that can be used are:-

ascending
If true (and sorting is allowed), re-sorts list in ascending order, otherwise descending.
page
Page in list cache to select (which starts at 1).
reload
If present and set to 'true', invalidates list cache, forcing it to reload using its current list finder.
select
Index of item in list cache to select (which starts at 0).
sort
Name of field to re-sort list, which must be recognised by the implementation of getItemSorter(java.lang.String, java.lang.Boolean).

Generic types:-

M
Record type of master list or Object if this displays the master list.
K
Primary key type of list cache.
T
Record type of list.
FT
Type of record that is type T formatted for display.
See Also:
  • Field Details

  • Constructor Details

    • AbstractViewListActionSupport

      public AbstractViewListActionSupport()
  • Method Details

    • checkRedirect

      protected String checkRedirect()
      Optionally written by subclasses to check if the main body of the execute function should not be run and returns the result it should return, usually a redirect result, or null for execute to continue.
    • endRecordFormatting

      protected void endRecordFormatting() throws Exception
      Optionally written by subclasses for cleanup after calls to startRecordFormatting() and formatRecord(M, T).
      Throws:
      Exception
    • formatRecord

      protected abstract FT formatRecord(M selectedMaster, T record)
      Written by subclasses to return formatted record for display from each list record to be displayed. This is called after startRecordFormatting() and before endRecordFormatting().
      Parameters:
      selectedMaster - Selected record of master list or null if this viewer action is for the master list. This may not have details if config.requireSelectedMasterDetail is false.
      record - Record from list that will be displayed. It may not have the additional details loaded.
    • getAlternateIndex

      protected Integer getAlternateIndex(ListCache<M,K,T> listCache)
      Optionally written by subclasses to return index of record to select, typically by a request parameter, or null for no change of selection.
    • getFindCommand

      protected ListFinder<M,T> getFindCommand(M selectedMaster) throws Exception
      May be overridden by subclasses to return Command object to replace current list finder and use it replace list, or null to skip this.
      Parameters:
      selectedMaster - Selected record of master list or null if loading master list.
      Throws:
      Exception
    • getFormatRecordIndex

      protected int getFormatRecordIndex()
      Returns index of record in list to be formatted. This is only used in formatRecord(M, T).
    • getItemSorter

      protected ListCacheRecordComparator<T> getItemSorter(String sortOption, Boolean sortAscending)
      May be overridden by subclasses to return a comparator that can sort entries in the list cache as requested by the user, or null to leave list order as is. This only applies if a sort order is requested and the list cache uses full list pagination mode.
      Parameters:
      sortOption - Value of sort parameter set by user.
      sortAscending - True if user set sort order to be ascending, false for descending, or null if not specified.
    • getListCache

      protected abstract ListCache<M,K,T> getListCache()
      Written by subclasses to return list cache that is being populated.
    • getMasterListCache

      protected abstract ListCache<?,?,M> getMasterListCache()
      Written by subclasses to return master list cache or null if the display list cache is the master list.
    • getViewListConfig

      protected abstract AbstractViewListActionSupport.ViewListConfig getViewListConfig()
      Written by subclasses to configure behaviour of view action.
    • getViewResponse

      protected String getViewResponse(M selectedMaster, T selectedItem) throws Exception
      May be overridden by subclasses to return the Struts 2 result name and, more likely, load additional data needed by the JSP. The list that will be displayed can be extracted getFormattedList(). This is called after endRecordFormatting().
      Parameters:
      selectedMaster - Selected record of master list or null if this viewer action is for the master list. This may not have details if config.requireSelectedMasterDetail is false.
      selectedItem - Selected record of list. This may not have details if config.requireSelectedItemDetail is false.
      Throws:
      Exception - Additional data for model cannot be retrieved.
    • startRecordFormatting

      protected void startRecordFormatting() throws Exception
      Optionally written by subclasses to prepare for calls to formatRecord(M, T). The records to be formatted are obtained from getUnformattedList().
      Throws:
      Exception
    • execute

      public String execute() throws Exception
      Specified by:
      execute in interface org.apache.struts2.action.Action
      Overrides:
      execute in class org.apache.struts2.ActionSupport
      Throws:
      Exception
    • getConfig

    • getFormattedList

      public FormattedListDisplay<FT> getFormattedList()
      Returns current page (which is entire list for non-page mode) of formatted records to be displayed.
    • getFormattedSelectedItem

      public FT getFormattedSelectedItem()
    • getExistingSelection

      public boolean getExistingSelection()
      Convenience function returning whether backing list cache has selected an existing item, typically to be updated, rather than a new one to create.
    • getUnformattedList

      public List<T> getUnformattedList()
      Returns current page (which is entire list for non-page mode) of unformatted records selected for formatting and display.
    • getUnformattedSelectedItem

      public T getUnformattedSelectedItem()