Class AbstractViewListActionSupport<M extends Serializable,K extends Serializable,T extends Serializable,FT>
- 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
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Configures list to be loaded by viewer action.Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.ValidationAware
com.opensymphony.xwork2.interceptor.ValidationAware.LegacyAdapter
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class org.apache.struts2.ActionSupport
container
Fields inherited from interface org.apache.struts2.action.Action
ERROR, INPUT, LOGIN, NONE, SUCCESS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
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.protected void
Optionally written by subclasses for cleanup after calls tostartRecordFormatting()
andformatRecord(M, T)
.execute()
protected abstract FT
formatRecord
(M selectedMaster, T record) Written by subclasses to return formatted record for display from each list record to be displayed.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.boolean
Convenience function returning whether backing list cache has selected an existing item, typically to be updated, rather than a new one to create.protected ListFinder
<M, T> getFindCommand
(M selectedMaster) May be overridden by subclasses to return Command object to replace current list finder and use it replace list, or null to skip this.protected int
Returns index of record in list to be formatted.Returns current page (which is entire list for non-page mode) of formatted records to be displayed.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.Written by subclasses to return list cache that is being populated.Written by subclasses to return master list cache or null if the display list cache is the master list.Returns current page (which is entire list for non-page mode) of unformatted records selected for formatting and display.protected abstract AbstractViewListActionSupport.ViewListConfig
Written by subclasses to configure behaviour of view action.protected String
getViewResponse
(M selectedMaster, T selectedItem) May be overridden by subclasses to return the Struts 2 result name and, more likely, load additional data needed by the JSP.protected void
Optionally written by subclasses to prepare for calls toformatRecord(M, T)
.Methods inherited from class name.matthewgreet.strutscommons.action.AbstractViewActionSupport
formatForms
Methods inherited from class name.matthewgreet.strutscommons.action.AbstractActionSupport
getBrowserTabSession, getLogger, getServletRequest, getTabId, setBrowserTabSession, setTabId, withServletRequest
Methods inherited from class org.apache.struts2.ActionSupport
addActionError, addActionMessage, addFieldError, clearActionErrors, clearErrors, clearErrorsAndMessages, clearFieldErrors, clearMessages, clone, getActionErrors, getActionMessages, getContainer, getFieldErrors, getFormatted, getLocale, getLocaleProvider, getText, getText, getText, getText, getText, getText, getText, getText, getText, getTextProvider, getTexts, getTexts, hasActionErrors, hasActionMessages, hasErrors, hasFieldErrors, hasKey, input, isValidLocale, isValidLocaleString, pause, setActionErrors, setActionMessages, setContainer, setFieldErrors, toLocale, validate
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface name.matthewgreet.strutscommons.action.BrowserTabAware2
copyAttributesFromOldTabToNewTab, handleAttributeFailures
Methods inherited from interface org.apache.struts2.Validateable
validate
Methods inherited from interface org.apache.struts2.interceptor.ValidationAware
addActionError, addActionMessage, addFieldError, getActionErrors, getActionMessages, getFieldErrors, hasActionErrors, hasActionMessages, hasErrors, hasFieldErrors, setActionErrors, setActionMessages, setFieldErrors
-
Field Details
-
PARAMETER_NAME_INDEXSELECT
- See Also:
-
PARAMETER_NAME_PAGE
- See Also:
-
PARAMETER_NAME_RELOAD
- See Also:
-
PARAMETER_VALUE_RELOAD_TRUE
- See Also:
-
PARAMETER_NAME_SORT_ASCENDING
- See Also:
-
PARAMETER_NAME_SORT_OPTION
- See Also:
-
PARAMETER_NAME_MASTER_INDEXSELECT
- See Also:
-
-
Constructor Details
-
AbstractViewListActionSupport
public AbstractViewListActionSupport()
-
-
Method Details
-
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
Optionally written by subclasses for cleanup after calls tostartRecordFormatting()
andformatRecord(M, T)
.- Throws:
Exception
-
formatRecord
Written by subclasses to return formatted record for display from each list record to be displayed. This is called afterstartRecordFormatting()
and beforeendRecordFormatting()
.- 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
Optionally written by subclasses to return index of record to select, typically by a request parameter, or null for no change of selection. -
getFindCommand
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 informatRecord(M, T)
. -
getItemSorter
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
Written by subclasses to return list cache that is being populated. -
getMasterListCache
Written by subclasses to return master list cache or null if the display list cache is the master list. -
getViewListConfig
Written by subclasses to configure behaviour of view action. -
getViewResponse
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 extractedgetFormattedList()
. This is called afterendRecordFormatting()
.- 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
Optionally written by subclasses to prepare for calls toformatRecord(M, T)
. The records to be formatted are obtained fromgetUnformattedList()
.- Throws:
Exception
-
execute
- Specified by:
execute
in interfaceorg.apache.struts2.action.Action
- Overrides:
execute
in classorg.apache.struts2.ActionSupport
- Throws:
Exception
-
getConfig
-
getFormattedList
Returns current page (which is entire list for non-page mode) of formatted records to be displayed. -
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
Returns current page (which is entire list for non-page mode) of unformatted records selected for formatting and display. -
getUnformattedSelectedItem
-