类 AbstractView
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.context.ApplicationContextAware,View
- 直接已知子类:
AbstractFeedView,AbstractJackson2View,AbstractPdfView,AbstractUrlBasedView,AbstractXlsView,MarshallingView
View
implementations. Subclasses should be JavaBeans, to allow for
convenient configuration as managed bean instances.
Provides support for static attributes, to be made available to the view, with a variety of ways to specify them. Static attributes will be merged with the given dynamic attributes (the model that the controller returned) for each render operation.
Extends WebApplicationObjectSupport, which will be helpful to
some views. Subclasses just need to implement the actual rendering.
- 从以下版本开始:
- 4.0
- 作者:
- Rod Johnson, Juergen Hoeller, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private Stringprivate Stringstatic final StringDefault content type.private booleanprivate booleanprivate booleanprivate static final intInitial size for the temporary output byte array (if any).private Stringprivate LinkedHashMap<String,Object> 从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor从接口继承的字段 cn.taketoday.web.view.View
RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidaddStaticAttribute(String name, Object value) Add static data to this view, exposed in each view.createMergedOutputModel(Map<String, ?> model, RequestContext context) Creates a combined output Map (nevernull) that includes dynamic values and static attributes.protected ByteArrayOutputStreamCreate a temporary OutputStream for this view.protected voidexposeModelAsRequestAttributes(Map<String, Object> model, RequestContext request) Expose the model objects in the given map as request attributes.protected Stringprotected booleanReturn whether this view generates download content (typically binary content like PDF or Excel files).Allow Map access to the static attributes of this view, with the option to add or override specific entries.Return the view's name.Return the content type for this view.Return the name of the RequestContext attribute, if any.protected RequestContextgetRequestContextToExpose(RequestContext original) Get the request handle to expose torenderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, cn.taketoday.web.RequestContext), i.e. to the view.Return the static attributes for this view.booleanReturn whether to add path variables to the model or not.protected voidprepareResponse(RequestContext context) Prepare the given response for rendering.voidrender(Map<String, ?> model, RequestContext context) Prepares the view given the specified model, merging it with static attributes and a RequestContext attribute, if necessary.protected abstract voidrenderMergedOutputModel(Map<String, Object> model, RequestContext request) Subclasses must implement this method to actually render the view.voidsetAttributes(Properties attributes) Set static attributes for this view from ajava.util.Propertiesobject.voidsetAttributesCSV(String propString) Set static attributes as a CSV string.voidsetAttributesMap(Map<String, ?> attributes) Set static attributes for this view from a Map.voidsetBeanName(String beanName) Set the view's name.voidsetContentType(String contentType) Set the content type for this view.voidsetExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) Set whether to make all beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed.voidsetExposedContextBeanNames(String... exposedContextBeanNames) Specify the names of beans in the context which are supposed to be exposed.voidsetExposeOutputRedirectModel(boolean exposeOutputRedirectModel) setexposeOutputRedirectModelto determine if all 'output' RedirectModel should be put into modelvoidsetExposePathVariables(boolean exposePathVariables) Specify whether to add path variables to the model or not.voidsetRequestContextAttribute(String requestContextAttribute) Set the name of the RequestContext attribute for this view.protected voidsetResponseContentType(RequestContext context) Set the content type of the response to the configuredcontent typeunless theView.SELECTED_CONTENT_TYPErequest attribute is present and set to a concrete media type.private LinkedHashMap<String,Object> toString()protected voidwriteToResponse(RequestContext response, ByteArrayOutputStream baos) Write the given temporary OutputStream to the HTTP response.从类继承的方法 cn.taketoday.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext, unwrapContext, unwrapFactory
-
字段详细资料
-
DEFAULT_CONTENT_TYPE
Default content type. Overridable as bean property.- 另请参阅:
-
OUTPUT_BYTE_ARRAY_INITIAL_SIZE
private static final int OUTPUT_BYTE_ARRAY_INITIAL_SIZEInitial size for the temporary output byte array (if any).- 另请参阅:
-
contentType
-
requestContextAttribute
-
staticAttributes
-
exposePathVariables
private boolean exposePathVariables -
exposeContextBeansAsAttributes
private boolean exposeContextBeansAsAttributes -
exposedContextBeanNames
-
beanName
-
exposeOutputRedirectModel
private boolean exposeOutputRedirectModel
-
-
构造器详细资料
-
AbstractView
public AbstractView()
-
-
方法详细资料
-
setContentType
Set the content type for this view. Default is "text/html;charset=UTF-8".May be ignored by subclasses if the view itself is assumed to set the content type, e.g. in case of JSPs.
-
getContentType
Return the content type for this view.- 指定者:
getContentType在接口中View- 返回:
- the content type String (optionally including a character set),
or
nullif not predetermined
-
setRequestContextAttribute
Set the name of the RequestContext attribute for this view. Default is none. -
getRequestContextAttribute
Return the name of the RequestContext attribute, if any. -
setAttributesCSV
Set static attributes as a CSV string. Format is: attname0={value1},attname1={value1}"Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model.
-
setAttributes
Set static attributes for this view from ajava.util.Propertiesobject."Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model.
This is the most convenient way to set static attributes. Note that static attributes can be overridden by dynamic attributes, if a value with the same name is included in the model.
Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions.
-
staticAttributes
-
setAttributesMap
Set static attributes for this view from a Map. This allows to set any kind of attribute values, for example bean references."Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model.
Can be populated with a "map" or "props" element in XML bean definitions.
- 参数:
attributes- a Map with name Strings as keys and attribute objects as values
-
getAttributesMap
Allow Map access to the static attributes of this view, with the option to add or override specific entries.Useful for specifying entries directly, for example via "attributesMap[myKey]". This is particularly useful for adding or overriding entries in child view definitions.
-
addStaticAttribute
Add static data to this view, exposed in each view."Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model.
Must be invoked before any calls to
render.- 参数:
name- the name of the attribute to exposevalue- the attribute value to expose- 另请参阅:
-
getStaticAttributes
Return the static attributes for this view. Handy for testing.Returns an unmodifiable Map, as this is not intended for manipulating the Map but rather just for checking the contents.
- 返回:
- the static attributes in this view
-
setExposePathVariables
public void setExposePathVariables(boolean exposePathVariables) Specify whether to add path variables to the model or not.Path variables are commonly bound to URI template variables through the
@PathVariableannotation. They're are effectively URI template variables with type conversion applied to them to derive typed Object values. Such values are frequently needed in views for constructing links to the same and other URLs.Path variables added to the model override static attributes (see
setAttributes(Properties)) but not attributes already present in the model.By default this flag is set to
true. Concrete view types can override this.- 参数:
exposePathVariables-trueto expose path variables, andfalseotherwise
-
isExposePathVariables
public boolean isExposePathVariables()Return whether to add path variables to the model or not. -
setExposeContextBeansAsAttributes
public void setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) Set whether to make all beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed.This will make all such beans accessible in plain
${...}expressions in a JSP 2.0 page, as well as in JSTL'sc:outvalue expressions.Default is "false". Switch this flag on to transparently expose all Framework beans in the request attribute namespace.
NOTE: Context beans will override any custom request or session attributes of the same name that have been manually added. However, model attributes (as explicitly exposed to this view) of the same name will always override context beans.
-
setExposedContextBeanNames
Specify the names of beans in the context which are supposed to be exposed. If this is non-null, only the specified beans are eligible for exposure as attributes.If you'd like to expose all Framework beans in the application context, switch the
"exposeContextBeansAsAttributes"flag on but do not list specific bean names for this property. -
setBeanName
Set the view's name. Helpful for traceability.Framework code must call this when constructing views.
- 指定者:
setBeanName在接口中cn.taketoday.beans.factory.BeanNameAware
-
getBeanName
Return the view's name. Should never benull, if the view was correctly configured. -
setExposeOutputRedirectModel
public void setExposeOutputRedirectModel(boolean exposeOutputRedirectModel) setexposeOutputRedirectModelto determine if all 'output' RedirectModel should be put into model- 参数:
exposeOutputRedirectModel- If true, all 'output' RedirectModel will be put to current view- 另请参阅:
-
render
Prepares the view given the specified model, merging it with static attributes and a RequestContext attribute, if necessary. Delegates to renderMergedOutputModel for the actual rendering. -
createMergedOutputModel
protected Map<String,Object> createMergedOutputModel(@Nullable Map<String, ?> model, RequestContext context) Creates a combined output Map (nevernull) that includes dynamic values and static attributes. Dynamic values take precedence over static attributes. -
prepareResponse
Prepare the given response for rendering.The default implementation applies a workaround for an IE bug when sending download content via HTTPS.
- 参数:
context- current HTTP request context
-
generatesDownloadContent
protected boolean generatesDownloadContent()Return whether this view generates download content (typically binary content like PDF or Excel files).The default implementation returns
false. Subclasses are encouraged to returntruehere if they know that they are generating download content that requires temporary caching on the client side, typically via the response OutputStream. -
getRequestContextToExpose
Get the request handle to expose torenderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, cn.taketoday.web.RequestContext), i.e. to the view.The default implementation wraps the original request for exposure of Framework beans as request attributes (if demanded).
- 参数:
original- the original request as provided by the engine- 返回:
- the wrapped request, or the original request if no wrapping is necessary
- 另请参阅:
-
renderMergedOutputModel
protected abstract void renderMergedOutputModel(Map<String, Object> model, RequestContext request) throws ExceptionSubclasses must implement this method to actually render the view.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.
- 参数:
model- combined output Map (nevernull), with dynamic values taking precedence over static attributesrequest- current HTTP request context- 抛出:
Exception- if rendering failed
-
exposeModelAsRequestAttributes
protected void exposeModelAsRequestAttributes(Map<String, Object> model, RequestContext request) throws ExceptionExpose the model objects in the given map as request attributes. Names will be taken from the model Map. This method is suitable for all resources reachable byRequestDispatcher.- 参数:
model- a Map of model objects to exposerequest- current HTTP request- 抛出:
Exception
-
createTemporaryOutputStream
Create a temporary OutputStream for this view.This is typically used as IE workaround, for setting the content length header from the temporary stream before actually writing the content to the HTTP response.
-
writeToResponse
protected void writeToResponse(RequestContext response, ByteArrayOutputStream baos) throws IOException Write the given temporary OutputStream to the HTTP response.- 参数:
response- current HTTP responsebaos- the temporary OutputStream to write- 抛出:
IOException- if writing/flushing failed
-
setResponseContentType
Set the content type of the response to the configuredcontent typeunless theView.SELECTED_CONTENT_TYPErequest attribute is present and set to a concrete media type. -
toString
-
formatViewName
-