Interface View
- All Known Subinterfaces:
FragmentsRendering
,SmartView
- All Known Implementing Classes:
AbstractAtomFeedView
,AbstractFeedView
,AbstractJackson2View
,AbstractPdfStamperView
,AbstractPdfView
,AbstractRssFeedView
,AbstractTemplateView
,AbstractUrlBasedView
,AbstractView
,AbstractXlsView
,AbstractXlsxStreamingView
,AbstractXlsxView
,FreeMarkerView
,GroovyMarkupView
,InternalResourceView
,JstlView
,MappingJackson2JsonView
,MappingJackson2XmlView
,MarshallingView
,RedirectView
,ScriptTemplateView
,XsltView
This class and the MVC approach associated with it is discussed in Chapter 12 of Expert One-On-One J2EE Design and Development by Rod Johnson (Wrox, 2002).
View implementations may differ widely. An obvious implementation would be JSP-based. Other implementations might be XSLT-based, or use an HTML generation library. This interface is designed to avoid restricting the range of possible implementations.
Views should be beans. They are likely to be instantiated as beans by a ViewResolver. As this interface is stateless, view implementations should be thread-safe.
- Author:
- Rod Johnson, Arjen Poutsma, Rossen Stoyanchev
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Name of theHttpServletRequest
attribute that contains a Map with path variables.static final String
Name of theHttpServletRequest
attribute that contains the response status code.static final String
TheMediaType
selected during content negotiation, which may be more specific than the one the View is configured with. -
Method Summary
Modifier and TypeMethodDescriptionReturn the content type of the view, if predetermined.void
render
(@Nullable Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) Render the view given the specified model.
-
Field Details
-
RESPONSE_STATUS_ATTRIBUTE
Name of theHttpServletRequest
attribute that contains the response status code.Note: This attribute is not required to be supported by all View implementations.
- Since:
- 3.0
-
PATH_VARIABLES
Name of theHttpServletRequest
attribute that contains a Map with path variables. The map consists of String-based URI template variable names as keys and their corresponding Object-based values -- extracted from segments of the URL and type converted.Note: This attribute is not required to be supported by all View implementations.
- Since:
- 3.1
-
SELECTED_CONTENT_TYPE
TheMediaType
selected during content negotiation, which may be more specific than the one the View is configured with. For example: "application/vnd.example-v1+xml" vs "application/*+xml".- Since:
- 3.2
-
-
Method Details
-
getContentType
Return the content type of the view, if predetermined.Can be used to check the view's content type upfront, i.e. before an actual rendering attempt.
- Returns:
- the content type String (optionally including a character set),
or
null
if not predetermined
-
render
void render(@Nullable Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws ExceptionRender the view given the specified model.The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.
- Parameters:
model
- a Map with name Strings as keys and corresponding model objects as values (Map can also benull
in case of empty model)request
- current HTTP requestresponse
- he HTTP response we are building- Throws:
Exception
- if rendering failed
-