类 AbstractView

    • 方法详细资料

      • setContentType

        public void setContentType​(String contentType)
        Set the content type for this view. Default is "text/html;charset=ISO-8859-1".

        May be ignored by subclasses if the view itself is assumed to set the content type, e.g. in case of JSPs.

      • getContentType

        public String getContentType()
        Return the content type for this view.
        指定者:
        getContentType 在接口中 View
        返回:
        the content type String (optionally including a character set), or null if not predetermined
      • setRequestContextAttribute

        public void setRequestContextAttribute​(String requestContextAttribute)
        Set the name of the RequestContext attribute for this view. Default is none.
      • setAttributesCSV

        public void setAttributesCSV​(String propString)
                              throws IllegalArgumentException
        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.

        抛出:
        IllegalArgumentException
      • setAttributes

        public void setAttributes​(Properties attributes)
        Set static attributes for this view from a java.util.Properties object.

        "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.

        另请参阅:
        PropertiesEditor
      • setAttributesMap

        public void setAttributesMap​(Map<String,​?> attributes)
        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

        public Map<String,​ObjectgetAttributesMap()
        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.

      • getStaticAttributes

        public Map<String,​ObjectgetStaticAttributes()
        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 @PathVariable annotation. 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 - true to expose path variables, and false otherwise
      • 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 Spring 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's c:out value expressions.

        Default is "false". Switch this flag on to transparently expose all Spring 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.

        另请参阅:
        getRequestToExpose(javax.servlet.http.HttpServletRequest)
      • setExposedContextBeanNames

        public void setExposedContextBeanNames​(String... exposedContextBeanNames)
        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 Spring beans in the application context, switch the "exposeContextBeansAsAttributes" flag on but do not list specific bean names for this property.

      • setBeanName

        public void setBeanName​(String beanName)
        Set the view's name. Helpful for traceability.

        Framework code must call this when constructing views.

        指定者:
        setBeanName 在接口中 BeanNameAware
        参数:
        beanName - the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils.originalBeanName(String) method to extract the original bean name (without suffix), if desired.
      • getBeanName

        public String getBeanName()
        Return the view's name. Should never be null, if the view was correctly configured.
      • prepareResponse

        protected void prepareResponse​(HttpServletRequest request,
                                       HttpServletResponse response)
        Prepare the given response for rendering.

        The default implementation applies a workaround for an IE bug when sending download content via HTTPS.

        参数:
        request - current HTTP request
        response - current HTTP response
      • renderMergedOutputModel

        protected abstract void renderMergedOutputModel​(Map<String,​Object> model,
                                                        HttpServletRequest request,
                                                        HttpServletResponse response)
                                                 throws Exception
        Subclasses 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 (never null), with dynamic values taking precedence over static attributes
        request - current HTTP request
        response - current HTTP response
        抛出:
        Exception - if rendering failed
      • createTemporaryOutputStream

        protected ByteArrayOutputStream 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.