V
- the type of view the controller supportspublic abstract class WidgetController<V> extends Object
Widget
instance which will be invoked to handle the request.
The instance is created with the help of a configurable WidgetFactory
which is by default
an instance of SimpleWidgetFactory
. The factory is passed the group and the type name of
the widget and additionally has access to the request parameters to select and instantiate the
correct widget class. The widget group and name can be provided as request parameters named
'widgetGroup' and 'widget'. Alternatively they can be part of the request URL which is expected
to look like /widgets/widgetGroup/widgetTypeName.widget The widgetGroup can contain slashes (in
both variants) for further structuring. Whether to parse the URL or check the parameters for
group and name can be defined with setUseRequestParametersForWidget(boolean)
. URL
parsing is the default.Modifier and Type | Field and Description |
---|---|
static String |
OBJECT_LIST
object list identifier in the view: If the result is a list it will be available in the
request after the widgets handleRequest has been called
|
static String |
OBJECT_SINGLE
single object result identifier in the view: If it the widgets result is a single reslult it
will be available in the request after the widgets handleRequest has been called
|
static String |
OBJECT_WIDGET
Widget identifier in the view: It will be available in the request after the widgets
handleRequest has been called
|
static String |
WIDGET_TYPE
widget type identifier (e.g.
|
Constructor and Description |
---|
WidgetController()
Default constructor
|
Modifier and Type | Method and Description |
---|---|
protected abstract V |
createMultiResultView(javax.servlet.http.HttpServletRequest request,
Widget widget,
List<?> result)
Creates and prepares the view to render the response of the widget request.
|
protected abstract V |
createSingleResultView(javax.servlet.http.HttpServletRequest request,
Widget widget,
Object result)
Creates and prepares the view to render the response of the widget request.
|
protected Widget |
getWidgetInstance(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Get the widget for the given request and configure it
|
V |
handleWidgetRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Parses the request, extracts the widget and invokes its query method.
|
void |
setAppendWidgetToTypeName(boolean appendWidget)
Whether to append the static string 'Widget' to all widget type names provided by URL or
request parameter.
|
void |
setUseRequestParametersForWidget(boolean useRequestParametersForWidget)
Determines how a widget is found.
|
void |
setWidgetFactory(WidgetFactory factory)
Set the factory to use for creating an instance of a widget that should handle a widget
request.
|
public static final String WIDGET_TYPE
public static final String OBJECT_SINGLE
public static final String OBJECT_LIST
public static final String OBJECT_WIDGET
protected abstract V createMultiResultView(javax.servlet.http.HttpServletRequest request, Widget widget, List<?> result)
request
- the requestwidget
- the widget that was invokedresult
- the result returned from the query method of the widgetprotected abstract V createSingleResultView(javax.servlet.http.HttpServletRequest request, Widget widget, Object result)
request
- the requestwidget
- the widget that was invokedresult
- the result returned from the query method of the widgetprotected Widget getWidgetInstance(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
request
- The requestresponse
- the response to usepublic V handleWidgetRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
createSingleResultView(HttpServletRequest, Widget, Object)
or
createMultiResultView(HttpServletRequest, Widget, List)
depending on the expected
result type of the widget.request
- the requestresponse
- the responsepublic void setAppendWidgetToTypeName(boolean appendWidget)
appendWidget
- true to append the static stringpublic void setUseRequestParametersForWidget(boolean useRequestParametersForWidget)
useRequestParametersForWidget
- true if the request parameters should be usedpublic void setWidgetFactory(WidgetFactory factory)
factory
- the factory to useCopyright © 2019 Communote team. All rights reserved.