org.springframework.webflow.mvc.view
Class AbstractMvcView

java.lang.Object
  extended by org.springframework.webflow.mvc.view.AbstractMvcView
All Implemented Interfaces:
View
Direct Known Subclasses:
PortletMvcView, ServletMvcView

public abstract class AbstractMvcView
extends java.lang.Object
implements View

Base view implementation for the Spring Web MVC Servlet and Spring Web MVC Portlet frameworks.

Author:
Keith Donald

Field Summary
 
Fields inherited from interface org.springframework.webflow.execution.View
RENDER_FRAGMENTS_ATTRIBUTE, USER_EVENT_STATE_ATTRIBUTE
 
Constructor Summary
AbstractMvcView(org.springframework.web.servlet.View view, RequestContext requestContext)
          Creates a new MVC view.
 
Method Summary
protected  java.lang.String determineEventId(RequestContext context)
          Obtain the user event from the current flow request.
protected abstract  void doRender(java.util.Map model)
          Template method subclasses should override to execute the view rendering logic.
protected  java.lang.String getEventId()
          Returns the id of the user event being processed.
 Event getFlowEvent()
          Get the flow event the current state should handle.
protected  MappingResults getMappingResults()
          Returns the results of binding to the view's model, if model binding has occurred.
protected  RequestContext getRequestContext()
          Returns the current flow request context.
 java.io.Serializable getUserEventState()
          A memento holding the results of processing a user event.
protected  org.springframework.web.servlet.View getView()
          Returns the Spring MVC view to render
 boolean hasFlowEvent()
          True if a call to View.processUserEvent() raised a flow event the current state should handle.
 void processUserEvent()
          Process the queued user event.
 void render()
          Render this view's content.
 void saveState()
          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(java.lang.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(java.lang.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.
protected  boolean shouldBind(java.lang.Object model, TransitionDefinition transition)
          Determines if model data binding should be invoked given the Transition that matched the current user event being processed.
 java.lang.String toString()
           
 boolean userEventQueued()
          True if there is a user event queued this view should process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMvcView

public AbstractMvcView(org.springframework.web.servlet.View view,
                       RequestContext requestContext)
Creates a new MVC view.

Parameters:
view - the Spring MVC view to render
requestContext - the current flow request context
Method Detail

setExpressionParser

public void setExpressionParser(ExpressionParser expressionParser)
Sets the expression parser to use to parse model expressions.

Parameters:
expressionParser - the expression parser

setConversionService

public void setConversionService(ConversionService conversionService)
Sets the service to use to expose formatters for field values.

Parameters:
conversionService - the conversion service

setBinderConfiguration

public void setBinderConfiguration(BinderConfiguration binderConfiguration)
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

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.


setEventIdParameterName

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

public void render()
            throws java.io.IOException
Description copied from interface: View
Render this view's content.

Specified by:
render in interface View
Throws:
java.io.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 interface View
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 when View.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 interface View
See Also:
View.hasFlowEvent()

getUserEventState

public java.io.Serializable 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 interface View
Returns:
the serializable user event state object, or null if no event state needs managing
See Also:
View.processUserEvent()

hasFlowEvent

public boolean hasFlowEvent()
Description copied from interface: View
True if a call to View.processUserEvent() raised a flow event the current state should handle. Call View.getFlowEvent() to access the Event.

Specified by:
hasFlowEvent in interface View
Returns:
true if yes, false otherwise

getFlowEvent

public Event getFlowEvent()
Description copied from interface: View
Get the flow event the current state should handle. Returns an Event object when View.hasFlowEvent() returns true. Returns null otherwise.

Specified by:
getFlowEvent in interface View
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 a ViewState 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.

Specified by:
saveState in interface View

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getRequestContext

protected RequestContext 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

doRender

protected abstract void doRender(java.util.Map model)
                          throws java.lang.Exception
Template method subclasses should override to execute the view rendering logic.

Parameters:
model - the view model data
Throws:
java.lang.Exception - an exception occurred rendering the view

getEventId

protected java.lang.String getEventId()
Returns the id of the user event being processed.

Returns:
the user event

shouldBind

protected boolean shouldBind(java.lang.Object model,
                             TransitionDefinition transition)
Determines if model data binding should be invoked given the Transition that matched the current user event being processed. Returns true unless the bind attribute of the Transition has been set to false. Subclasses may override.

Parameters:
model - the model data binding would be performed on
transition - the matched transition
Returns:
true if binding should occur, false if not

getMappingResults

protected MappingResults getMappingResults()
Returns the results of binding to the view's model, if model binding has occurred.

Returns:
the binding (mapping) results

determineEventId

protected java.lang.String determineEventId(RequestContext context)
Obtain the user event from the current flow request. The default implementation returns the value of the request parameter with name eventIdParameterName. Subclasses may override.

Parameters:
context - the current flow request context
Returns:
the user event that occurred