Spring Web Flow

org.springframework.webflow.mvc.builder
Class MvcViewFactoryCreator

java.lang.Object
  extended by org.springframework.webflow.mvc.builder.MvcViewFactoryCreator
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, ViewFactoryCreator

public class MvcViewFactoryCreator
extends java.lang.Object
implements ViewFactoryCreator, org.springframework.context.ApplicationContextAware

Returns view factories that create native Spring MVC-based views. Used by a FlowBuilder to configure a flow's view states with Spring MVC-based view factories.

This implementation detects whether it is running in a Servlet or Portlet MVC environment, and returns instances of the default view factory implementation for that environment.

By default, this implementation creates view factories that resolve their views by loading flow-relative resources, such as .jsp templates located in a flow working directory. This class also supports rendering views resolved by pre-existing Spring MVC view resolvers.

Author:
Keith Donald, Scott Andrews
See Also:
ServletMvcViewFactory, PortletMvcViewFactory, FlowResourceFlowViewResolver, DelegatingFlowViewResolver

Constructor Summary
MvcViewFactoryCreator()
          Create a new Spring MVC View Factory Creator.
 
Method Summary
protected  AbstractMvcViewFactory createMvcViewFactory(Expression viewId, ExpressionParser expressionParser, ConversionService conversionService, BinderConfiguration binderConfiguration)
          Creates a concrete instance of an AbstractMvcViewFactory according to the runtime environment (Servlet or Portlet).
 ViewFactory createViewFactory(Expression viewId, ExpressionParser expressionParser, ConversionService conversionService, BinderConfiguration binderConfiguration, org.springframework.validation.Validator validator, ValidationHintResolver validationHintResolver)
          Create a view factory capable of creating View objects that can render the view template with the provided identifier.
 java.lang.String getViewIdByConvention(java.lang.String viewStateId)
          Get the default id of the view to render in the provided view state by convention.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setDefaultViewSuffix(java.lang.String defaultViewSuffix)
          Configure an FlowResourceFlowViewResolver capable of resolving view resources by applying the specified default resource suffix.
 void setEventIdParameterName(java.lang.String eventIdParameterName)
          Sets the name of the request parameter to use to lookup user events signaled by views created in this factory.
 void setFieldMarkerPrefix(java.lang.String fieldMarkerPrefix)
          Specify a prefix that can be used for parameters that mark potentially empty fields, having "prefix + field" as name.
 void setFlowViewResolver(FlowViewResolver flowViewResolver)
          Set to fully customize how the flow system resolves Spring MVC View objects.
 void setMessageCodesResolver(org.springframework.validation.MessageCodesResolver messageCodesResolver)
          Sets the message codes resolver strategy to use to resolve bind and validation error message codes.
 void setUseSpringBeanBinding(boolean useSpringBeanBinding)
          Sets whether to use data binding with Spring's BeanWrapper should be enabled.
 void setViewResolvers(java.util.List<org.springframework.web.servlet.ViewResolver> viewResolvers)
          Sets the chain of Spring MVC view resolvers to delegate to resolve views selected by flows.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MvcViewFactoryCreator

public MvcViewFactoryCreator()
Create a new Spring MVC View Factory Creator.

See Also:
setDefaultViewSuffix(String), setEventIdParameterName(String), setFieldMarkerPrefix(String), setUseSpringBeanBinding(boolean), setFlowViewResolver(FlowViewResolver), setViewResolvers(List), setMessageCodesResolver(MessageCodesResolver)
Method Detail

setDefaultViewSuffix

public void setDefaultViewSuffix(java.lang.String defaultViewSuffix)
Configure an FlowResourceFlowViewResolver capable of resolving view resources by applying the specified default resource suffix. Default is .jsp.

Parameters:
defaultViewSuffix - the default view suffix

setEventIdParameterName

public void setEventIdParameterName(java.lang.String eventIdParameterName)
Sets the name of the request parameter to use to lookup user events signaled by views created in this factory. If not specified, the default is _eventId

Parameters:
eventIdParameterName - the event id parameter name

setFieldMarkerPrefix

public void setFieldMarkerPrefix(java.lang.String fieldMarkerPrefix)
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.


setUseSpringBeanBinding

public void setUseSpringBeanBinding(boolean useSpringBeanBinding)
Sets whether to use data binding with Spring's BeanWrapper should be enabled. Set to 'true' to enable. 'false', disabled, is the default. With this enabled, the same binding system used by Spring MVC 2.x is also used in a Web Flow environment.

Parameters:
useSpringBeanBinding - the Spring bean binding flag

setFlowViewResolver

public void setFlowViewResolver(FlowViewResolver flowViewResolver)
Set to fully customize how the flow system resolves Spring MVC View objects.

Parameters:
flowViewResolver - the flow view resolver

setViewResolvers

public void setViewResolvers(java.util.List<org.springframework.web.servlet.ViewResolver> viewResolvers)
Sets the chain of Spring MVC view resolvers to delegate to resolve views selected by flows. Allows for reuse of existing View Resolvers configured in a Spring application context. If multiple resolvers are to be used, the resolvers should be ordered in the manner they should be applied.

Parameters:
viewResolvers - the view resolver list

setMessageCodesResolver

public void setMessageCodesResolver(org.springframework.validation.MessageCodesResolver messageCodesResolver)
Sets the message codes resolver strategy to use to resolve bind and validation error message codes. If not set, WebFlowMessageCodesResolver is the default. Plug in a DefaultMessageCodesResolver to resolve message codes consistently between Spring MVC Controllers and Web Flow.

Parameters:
messageCodesResolver - the message codes resolver

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware

createViewFactory

public ViewFactory createViewFactory(Expression viewId,
                                     ExpressionParser expressionParser,
                                     ConversionService conversionService,
                                     BinderConfiguration binderConfiguration,
                                     org.springframework.validation.Validator validator,
                                     ValidationHintResolver validationHintResolver)
Description copied from interface: ViewFactoryCreator
Create a view factory capable of creating View objects that can render the view template with the provided identifier.

Specified by:
createViewFactory in interface ViewFactoryCreator
Parameters:
viewId - an expression that resolves the id of the view to render
expressionParser - an optional expression parser to use to resolve view expressions
conversionService - an optional conversion service to use to format text values
binderConfiguration - information on how the rendered view binds to a model that provides its data
validator - a global validator to invoke
validationHintResolver - a custom ValidationHintResolver to use
Returns:
the view factory

createMvcViewFactory

protected AbstractMvcViewFactory createMvcViewFactory(Expression viewId,
                                                      ExpressionParser expressionParser,
                                                      ConversionService conversionService,
                                                      BinderConfiguration binderConfiguration)
Creates a concrete instance of an AbstractMvcViewFactory according to the runtime environment (Servlet or Portlet).


getViewIdByConvention

public java.lang.String getViewIdByConvention(java.lang.String viewStateId)
Description copied from interface: ViewFactoryCreator
Get the default id of the view to render in the provided view state by convention.

Specified by:
getViewIdByConvention in interface ViewFactoryCreator
Parameters:
viewStateId - the view state id
Returns:
the default view id

Spring Web Flow