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
ConstructorsConstructorDescriptionAbstractMvcView(org.springframework.web.servlet.View view, RequestContext requestContext) Creates a new MVC view. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddDefaultMapping(DefaultMapper mapper, String parameter, Object model) Adds aDefaultMappingbetween the given request parameter name and a matching model field.protected voidaddDefaultMappings(DefaultMapper mapper, Set<String> parameterNames, Object model) Add aDefaultMappinginstance for all incoming request parameters except those having a special field marker prefix.protected voidaddEmptyValueMapping(DefaultMapper mapper, String field, Object model) Adds a specialDefaultMappingthat results in setting the target field on the model to an empty value (typically null).protected voidaddMapping(DefaultMapper mapper, BinderConfiguration.Binding binding, Object model) Creates and adds aDefaultMappingfor the givenBinderConfiguration.Binding.protected voidaddModelBindings(DefaultMapper mapper, Set<String> parameterNames, Object model) Adds aDefaultMappingfor every configured viewBinderConfiguration.Bindingfor which there is an incoming request parameter.protected MappingResultsCauses the model to be populated from information contained in request parameters.protected MessageResolverprotected StringdetermineEventId(RequestContext context) Obtain the user event from the current flow request.protected abstract voidTemplate method subclasses should override to execute the view rendering logic.protected BinderConfigurationReturns the binding configuration that defines how to connect properties of the model to UI elements.protected ConversionServiceprotected StringReturns the id of the user event being processed.protected ExpressionParserReturns the EL parser to be used for data binding purposes.protected StringReturns the prefix that can be used for parameters that mark potentially empty fields.Get the flow event the current state should handle.protected MappingResultsReturns the results of binding to the view's model, if model binding has occurred.protected RequestContextReturns the current flow request context.A memento holding the results of processing a user event.protected org.springframework.web.servlet.ViewgetView()Returns the Spring MVC view to renderbooleanTrue if a call toView.processUserEvent()raised a flow event the current state should handle.voidProcess the queued user event.voidrender()Render this view's content.voidSaves any state associated with this view out to view scope.voidsetBinderConfiguration(BinderConfiguration binderConfiguration) Sets the configuration describing how this view should bind to its model to access data for rendering.voidsetConversionService(ConversionService conversionService) Sets the service to use to expose formatters for field values.voidsetEventIdParameterName(String eventIdParameterName) Sets the name of the request parameter to use to lookup user events signaled by this view.voidsetExpressionParser(ExpressionParser expressionParser) Sets the expression parser to use to parse model expressions.voidsetFieldMarkerPrefix(String fieldMarkerPrefix) Specify a prefix that can be used for parameters that mark potentially empty fields, having "prefix + field" as name.voidsetMessageCodesResolver(org.springframework.validation.MessageCodesResolver messageCodesResolver) Set the message codes resolver to use to resolve bind and validation failure message codes.voidsetValidationHintResolver(ValidationHintResolver validationHintResolver) voidsetValidator(org.springframework.validation.Validator validator) protected booleanshouldBind(Object model, TransitionDefinition transition) Determines if model data binding should be invoked given the Transition that matched the current user event being processed.protected booleanshouldValidate(Object model, TransitionDefinition transition) Determines if model validation should execute given the Transition that matched the current user event being processed.toString()booleanTrue 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:ViewRender this view's content.- Specified by:
renderin interfaceView- Throws:
IOException- if an IO Exception occured rendering the view
-
userEventQueued
public boolean userEventQueued()Description copied from interface:ViewTrue if there is a user event queued this view should process.- Specified by:
userEventQueuedin interfaceView- Returns:
- true if a user event is queued, false if not
-
processUserEvent
public void processUserEvent()Description copied from interface:ViewProcess 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:
processUserEventin interfaceView- See Also:
-
getUserEventState
Description copied from interface:ViewA 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:
getUserEventStatein 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:ViewTrue if a call toView.processUserEvent()raised a flow event the current state should handle. CallView.getFlowEvent()to access the Event.- Specified by:
hasFlowEventin interfaceView- Returns:
- true if yes, false otherwise
-
getFlowEvent
Description copied from interface:ViewGet the flow event the current state should handle. Returns an Event object whenView.hasFlowEvent()returns true. Returnsnullotherwise.- Specified by:
getFlowEventin interfaceView- Returns:
- the event, or
nullif there is no event for the flow system to handle
-
saveState
public void saveState()Description copied from interface:ViewSaves any state associated with this view out to view scope. Called when exiting aViewStateto 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 thebindattribute 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
BinderConfigurationor 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
DefaultMappingfor every configured viewBinderConfiguration.Bindingfor 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
DefaultMappingfor 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 aDefaultMappinginstance 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 specialDefaultMappingthat 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 aDefaultMappingbetween 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 thevalidateattribute of the Transition has been set to false, or model data binding errors occurred and the globalvalidateOnBindingErrorsflag 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
-