Class AbstractMvcView
- All Implemented Interfaces:
View
- Direct Known Subclasses:
ServletMvcView
- Author:
- Keith Donald
-
Field Summary
Fields inherited from interface org.springframework.webflow.execution.View
RENDER_FRAGMENTS_ATTRIBUTE, USER_EVENT_STATE_ATTRIBUTE
-
Constructor Summary
ConstructorDescriptionAbstractMvcView
(org.springframework.web.servlet.View view, RequestContext requestContext) Creates a new MVC view. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addDefaultMapping
(DefaultMapper mapper, String parameter, Object model) Adds aDefaultMapping
between the given request parameter name and a matching model field.protected void
addDefaultMappings
(DefaultMapper mapper, Set<String> parameterNames, Object model) Add aDefaultMapping
instance for all incoming request parameters except those having a special field marker prefix.protected void
addEmptyValueMapping
(DefaultMapper mapper, String field, Object model) Adds a specialDefaultMapping
that results in setting the target field on the model to an empty value (typically null).protected void
addMapping
(DefaultMapper mapper, BinderConfiguration.Binding binding, Object model) Creates and adds aDefaultMapping
for the givenBinderConfiguration.Binding
.protected void
addModelBindings
(DefaultMapper mapper, Set<String> parameterNames, Object model) Adds aDefaultMapping
for every configured viewBinderConfiguration.Binding
for which there is an incoming request parameter.protected MappingResults
Causes the model to be populated from information contained in request parameters.protected MessageResolver
protected String
determineEventId
(RequestContext context) Obtain the user event from the current flow request.protected abstract void
Template method subclasses should override to execute the view rendering logic.protected BinderConfiguration
Returns the binding configuration that defines how to connect properties of the model to UI elements.protected ConversionService
protected String
Returns the id of the user event being processed.protected ExpressionParser
Returns the EL parser to be used for data binding purposes.protected String
Returns the prefix that can be used for parameters that mark potentially empty fields.Get the flow event the current state should handle.protected MappingResults
Returns the results of binding to the view's model, if model binding has occurred.protected RequestContext
Returns the current flow request context.A memento holding the results of processing a user event.protected org.springframework.web.servlet.View
getView()
Returns the Spring MVC view to renderboolean
True if a call toView.processUserEvent()
raised a flow event the current state should handle.void
Process the queued user event.void
render()
Render this view's content.void
Saves any state associated with this view out to view scope.void
setBinderConfiguration
(BinderConfiguration binderConfiguration) Sets the configuration describing how this view should bind to its model to access data for rendering.void
setConversionService
(ConversionService conversionService) Sets the service to use to expose formatters for field values.void
setEventIdParameterName
(String eventIdParameterName) Sets the name of the request parameter to use to lookup user events signaled by this view.void
setExpressionParser
(ExpressionParser expressionParser) Sets the expression parser to use to parse model expressions.void
setFieldMarkerPrefix
(String fieldMarkerPrefix) Specify a prefix that can be used for parameters that mark potentially empty fields, having "prefix + field" as name.void
setMessageCodesResolver
(org.springframework.validation.MessageCodesResolver messageCodesResolver) Set the message codes resolver to use to resolve bind and validation failure message codes.void
setValidationHintResolver
(ValidationHintResolver validationHintResolver) void
setValidator
(org.springframework.validation.Validator validator) protected boolean
shouldBind
(Object model, TransitionDefinition transition) Determines if model data binding should be invoked given the Transition that matched the current user event being processed.protected boolean
shouldValidate
(Object model, TransitionDefinition transition) Determines if model validation should execute given the Transition that matched the current user event being processed.toString()
boolean
True if there is a user event queued this view should process.
-
Constructor Details
-
AbstractMvcView
Creates a new MVC view.- Parameters:
view
- the Spring MVC view to renderrequestContext
- the current flow request context
-
-
Method Details
-
setExpressionParser
Sets the expression parser to use to parse model expressions.- Parameters:
expressionParser
- the expression parser
-
setConversionService
Sets the service to use to expose formatters for field values.- Parameters:
conversionService
- the conversion service
-
setValidator
public void setValidator(org.springframework.validation.Validator validator) -
setValidationHintResolver
-
setBinderConfiguration
Sets the configuration describing how this view should bind to its model to access data for rendering.- Parameters:
binderConfiguration
- the model binder configuration
-
setMessageCodesResolver
public void setMessageCodesResolver(org.springframework.validation.MessageCodesResolver messageCodesResolver) Set the message codes resolver to use to resolve bind and validation failure message codes.- Parameters:
messageCodesResolver
- the binding error message code resolver to use
-
setFieldMarkerPrefix
Specify a prefix that can be used for parameters that mark potentially empty fields, having "prefix + field" as name. Such a marker parameter is checked by existence: You can send any value for it, for example "visible". This is particularly useful for HTML checkboxes and select options.Default is "_", for "_FIELD" parameters (e.g. "_subscribeToNewsletter"). Set this to null if you want to turn off the empty field check completely.
HTML checkboxes only send a value when they're checked, so it is not possible to detect that a formerly checked box has just been unchecked, at least not with standard HTML means.
This auto-reset mechanism addresses this deficiency, provided that a marker parameter is sent for each checkbox field, like "_subscribeToNewsletter" for a "subscribeToNewsletter" field. As the marker parameter is sent in any case, the data binder can detect an empty field and automatically reset its value.
-
setEventIdParameterName
Sets the name of the request parameter to use to lookup user events signaled by this view. If not specified, the default is_eventId
- Parameters:
eventIdParameterName
- the event id parameter name
-
render
Description copied from interface:View
Render this view's content.- Specified by:
render
in interfaceView
- Throws:
IOException
- if an IO Exception occured rendering the view
-
userEventQueued
public boolean userEventQueued()Description copied from interface:View
True if there is a user event queued this view should process.- Specified by:
userEventQueued
in interfaceView
- Returns:
- true if a user event is queued, false if not
-
processUserEvent
public void processUserEvent()Description copied from interface:View
Process the queued user event. Should only be called whenView.userEventQueued()
returns true. After calling this method, a flow event may be raised that should be handled in the Web Flow system.- Specified by:
processUserEvent
in interfaceView
- See Also:
-
getUserEventState
Description copied from interface:View
A memento holding the results of processing a user event. Used to allow transient view state such as binding and validation errors to survive a flow execution redirect.- Specified by:
getUserEventState
in interfaceView
- Returns:
- the serializable user event state object, or null if no event state needs managing
- See Also:
-
hasFlowEvent
public boolean hasFlowEvent()Description copied from interface:View
True if a call toView.processUserEvent()
raised a flow event the current state should handle. CallView.getFlowEvent()
to access the Event.- Specified by:
hasFlowEvent
in interfaceView
- Returns:
- true if yes, false otherwise
-
getFlowEvent
Description copied from interface:View
Get the flow event the current state should handle. Returns an Event object whenView.hasFlowEvent()
returns true. Returnsnull
otherwise.- Specified by:
getFlowEvent
in interfaceView
- Returns:
- the event, or
null
if there is no event for the flow system to handle
-
saveState
public void saveState()Description copied from interface:View
Saves any state associated with this view out to view scope. Called when exiting aViewState
to allow for any changes applied after postback processing to be captured and reflected when going back. Can be a no-op for views that store no view state. -
toString
-
getRequestContext
Returns the current flow request context.- Returns:
- the flow request context
-
getView
protected org.springframework.web.servlet.View getView()Returns the Spring MVC view to render- Returns:
- the view
-
getConversionService
- Returns:
- the configured ConversionService
-
doRender
Template method subclasses should override to execute the view rendering logic.- Parameters:
model
- the view model data- Throws:
Exception
- an exception occurred rendering the view
-
getEventId
Returns the id of the user event being processed.- Returns:
- the user event
-
shouldBind
Determines if model data binding should be invoked given the Transition that matched the current user event being processed. Returns true unless thebind
attribute of the Transition has been set to false. Subclasses may override.- Parameters:
model
- the model data binding would be performed ontransition
- the matched transition- Returns:
- true if binding should occur, false if not
-
getMappingResults
Returns the results of binding to the view's model, if model binding has occurred.- Returns:
- the binding (mapping) results
-
getBinderConfiguration
Returns the binding configuration that defines how to connect properties of the model to UI elements.- Returns:
- an instance of
BinderConfiguration
or null.
-
getExpressionParser
Returns the EL parser to be used for data binding purposes.- Returns:
- an instance of
ExpressionParser
.
-
getFieldMarkerPrefix
Returns the prefix that can be used for parameters that mark potentially empty fields.- Returns:
- the prefix value.
-
determineEventId
Obtain the user event from the current flow request. The default implementation returns the value of the request parameter with nameeventIdParameterName
. Subclasses may override.- Parameters:
context
- the current flow request context- Returns:
- the user event that occurred
-
bind
Causes the model to be populated from information contained in request parameters.
If a view has binding configuration then only model fields specified in the binding configuration will be considered. In the absence of binding configuration all request parameters will be used to update matching fields on the model.
- Parameters:
model
- the model to be updated- Returns:
- an instance of MappingResults with information about the results of the binding.
-
addModelBindings
Adds a
DefaultMapping
for every configured viewBinderConfiguration.Binding
for which there is an incoming request parameter. If there is no matching incoming request parameter, a special mapping is created that will set the target field on the model to an empty value (typically null).- Parameters:
mapper
- the mapper to which mappings will be addedparameterNames
- the request parametersmodel
- the model
-
addMapping
Creates and adds a
DefaultMapping
for the givenBinderConfiguration.Binding
. Information such as the model field name, if the field is required, and whether type conversion is needed will be passed on from the binding to the mapping.Note: with Spring 3 type conversion and formatting now in use in Web Flow, it is no longer necessary to use named converters on binding elements. The preferred approach is to register Spring 3 formatters. Named converters are supported for backwards compatibility only and will not result in use of the Spring 3 type conversion system at runtime.
- Parameters:
mapper
- the mapper to add the mapping tobinding
- the binding elementmodel
- the model
-
addDefaultMappings
Add aDefaultMapping
instance for all incoming request parameters except those having a special field marker prefix. This method is used when binding configuration was not specified on the view.- Parameters:
mapper
- the mapper to add mappings toparameterNames
- the request parameter namesmodel
- the model
-
addEmptyValueMapping
Adds a specialDefaultMapping
that results in setting the target field on the model to an empty value (typically null).- Parameters:
mapper
- the mapper to add the mapping tofield
- the field for which a mapping is to be addedmodel
- the model
-
addDefaultMapping
Adds aDefaultMapping
between the given request parameter name and a matching model field.- Parameters:
mapper
- the mapper to add the mapping toparameter
- the request parameter namemodel
- the model
-
shouldValidate
Determines if model validation should execute given the Transition that matched the current user event being processed. Returns true unless thevalidate
attribute of the Transition has been set to false, or model data binding errors occurred and the globalvalidateOnBindingErrors
flag is set to false. Subclasses may override.- Parameters:
model
- the model data binding would be performed ontransition
- the matched transition- Returns:
- true if binding should occur, false if not
-
createMessageResolver
-