Class WSuggestions
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WSuggestions
-
- All Implemented Interfaces:
AjaxInternalTrigger,AjaxTarget,WComponent,WebComponent,Serializable
public class WSuggestions extends AbstractWComponent implements AjaxInternalTrigger, AjaxTarget
WSuggestions represents a device for providing suggested input for a text-like input field. The suggestions may be a static list, derived from a data url or acquired on the fly (via AJAX) based on user input into an associated input.WSuggestions has no effect unless it is associated with a text-like input control such as WTextField. If it is associated with a constrained input (such as WEmailField) then it is expected (but not enforced) that the suggestions would be in line with the associated field's constraints.
It allows for client caching of frequently used lists via a data key or lists that can be produced via AJAX depending on the text entered in the related TextField.
Suggestions provided via a lookup table are cached on the client and filtered on the client.
To have a suggestion list dynamically updated via AJAX, do not use a lookup table, but manually set the options and set a refresh action via
setRefreshAction(Action). The text entered by the user that triggered the refresh is provided bygetAjaxFilter().- Since:
- 1.0.0
- Author:
- Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWSuggestions.AutocompleteThe way in which the suggestion is provided to and selected by the user.static classWSuggestions.SuggestionsModelA class used to hold the list of options for this component.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
Fields Modifier and Type Field Description static StringAJAX_REFRESH_ACTION_COMMANDAJAX refresh command.-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Constructor Summary
Constructors Constructor Description WSuggestions()Create a WSuggestions.WSuggestions(Object lookupTable)Creates a WSuggestions using a lookup table for the suggestions.WSuggestions(List<String> suggestions)Creates a WSuggestions with predefined suggestions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoHandleAjaxRefresh()Handle the AJAX refresh request.StringgetAjaxFilter()WSuggestions.AutocompletegetAutocomplete()protected WSuggestions.SuggestionsModelgetComponentModel()Returns the effective component model for this component.StringgetListCacheKey()Retrieves the data list cache key for this component.ObjectgetLookupTable()Get the lookupTable for this user's session.intgetMinRefresh()The minimum characters entered before triggering the refresh action.protected WSuggestions.SuggestionsModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.ActiongetRefreshAction()List<String>getSuggestions()Returns the complete list of suggestions available for selection for this user's session.voidhandleRequest(Request request)Subclasses should override this method in order to provide specific request handling logic.protected WSuggestions.SuggestionsModelnewComponentModel()Creates a new component model appropriate for this component.protected voidsetAjaxFilter(String filter)voidsetAutocomplete(WSuggestions.Autocomplete autocomplete)voidsetLookupTable(Object lookupTable)Set the lookupTable for this user's session.voidsetMinRefresh(int min)The minimum number of characters entered before refreshing suggestions.voidsetRefreshAction(Action action)voidsetSuggestions(List<String> suggestions)Set the complete list of suggestions available for selection for this user's session.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, toString, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Field Detail
-
AJAX_REFRESH_ACTION_COMMAND
public static final String AJAX_REFRESH_ACTION_COMMAND
AJAX refresh command.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WSuggestions
public WSuggestions()
Create a WSuggestions.
-
WSuggestions
public WSuggestions(List<String> suggestions)
Creates a WSuggestions with predefined suggestions.- Parameters:
suggestions- the list of suggestions.
-
WSuggestions
public WSuggestions(Object lookupTable)
Creates a WSuggestions using a lookup table for the suggestions.- Parameters:
lookupTable- the lookup table identifier to obtain the list of suggestions.
-
-
Method Detail
-
handleRequest
public void handleRequest(Request request)
Subclasses should override this method in order to provide specific request handling logic. For example, a text field may set its value to the value of a request parameter.- Specified by:
handleRequestin interfaceWComponent- Overrides:
handleRequestin classAbstractWComponent- Parameters:
request- the request being responded to.
-
doHandleAjaxRefresh
protected void doHandleAjaxRefresh()
Handle the AJAX refresh request.
-
getSuggestions
public List<String> getSuggestions()
Returns the complete list of suggestions available for selection for this user's session.- Returns:
- the list of suggestions available for the given user's session.
-
getListCacheKey
public String getListCacheKey()
Retrieves the data list cache key for this component.- Returns:
- the cache key if client-side caching is enabled, null otherwise.
-
setSuggestions
public void setSuggestions(List<String> suggestions)
Set the complete list of suggestions available for selection for this user's session.- Parameters:
suggestions- the list of suggestions available to the user.
-
setLookupTable
public void setLookupTable(Object lookupTable)
Set the lookupTable for this user's session.- Parameters:
lookupTable- the lookup table identifier to obtain the suggestions for the list.
-
getLookupTable
public Object getLookupTable()
Get the lookupTable for this user's session.- Returns:
- the lookupTable for the suggestions
-
setRefreshAction
public void setRefreshAction(Action action)
- Parameters:
action- the refresh action. Ignored if using a lookup table.
-
getRefreshAction
public Action getRefreshAction()
- Returns:
- the refresh action. Ignored if using a lookup table.
-
setAjaxFilter
protected void setAjaxFilter(String filter)
- Parameters:
filter- the refresh filter value passed on the AJAX request.
-
getAjaxFilter
public String getAjaxFilter()
- Returns:
- the refresh filter value passed on the AJAX request. Ignored if using a lookup table.
-
setAutocomplete
public void setAutocomplete(WSuggestions.Autocomplete autocomplete)
- Parameters:
autocomplete- The Autocomplete to set for this instance.
-
getAutocomplete
public WSuggestions.Autocomplete getAutocomplete()
- Returns:
- The autocomplete for this instance.
-
setMinRefresh
public void setMinRefresh(int min)
The minimum number of characters entered before refreshing suggestions. A value of zero indicates to use the theme default, which is usually 3.- Parameters:
min- the minimum number of characters entered before refreshing suggestions.
-
getMinRefresh
public int getMinRefresh()
The minimum characters entered before triggering the refresh action.A value of zero indicates the theme default will be used (usually 3).
- Returns:
- the minimum characters entered before triggering the refresh action.
-
getComponentModel
protected WSuggestions.SuggestionsModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModelin classAbstractWComponent- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WSuggestions.SuggestionsModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModelin classAbstractWComponent- Returns:
- the model for this component
-
newComponentModel
protected WSuggestions.SuggestionsModel newComponentModel()
Creates a new component model appropriate for this component.- Overrides:
newComponentModelin classAbstractWComponent- Returns:
- a new PanelModel.
-
-