org.springframework.web.method.support

Class ModelAndViewContainer

  • java.lang.Object
    • org.springframework.web.method.support.ModelAndViewContainer
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      ModelAndViewContainer addAllAttributes(java.util.Map<java.lang.String,?> attributes)
      Copy all attributes to the underlying model.
      ModelAndViewContainer addAttribute(java.lang.Object value)
      Add the supplied attribute to the underlying model.
      ModelAndViewContainer addAttribute(java.lang.String name, java.lang.Object value)
      Add the supplied attribute to the underlying model.
      boolean containsAttribute(java.lang.String name)
      Whether the underlying model contains the given attribute name.
      ModelMap getDefaultModel()
      Return the "default" model created at instantiation.
      ModelMap getModel()
      Return the model to use -- either the "default" or the "redirect" model.
      SessionStatus getSessionStatus()
      Return the SessionStatus instance to use that can be used to signal that session processing is complete.
      HttpStatus getStatus()
      Return the configured HTTP status, if any.
      java.lang.Object getView()
      Return the View object, or null if we using a view name to be resolved by the DispatcherServlet via a ViewResolver.
      java.lang.String getViewName()
      Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if a View object is set.
      boolean isBindingDisabled(java.lang.String name)
      Whether binding is disabled for the given model attribute.
      boolean isRequestHandled()
      Whether the request has been handled fully within the handler.
      boolean isViewReference()
      Whether the view is a view reference specified via a name to be resolved by the DispatcherServlet via a ViewResolver.
      ModelAndViewContainer mergeAttributes(java.util.Map<java.lang.String,?> attributes)
      Copy attributes in the supplied Map with existing objects of the same name taking precedence (i.e.
      ModelAndViewContainer removeAttributes(java.util.Map<java.lang.String,?> attributes)
      Remove the given attributes from the model.
      void setBinding(java.lang.String attributeName, boolean enabled)
      Register whether data binding should occur for a corresponding model attribute, corresponding to an @ModelAttribute(binding=true/false) declaration.
      void setBindingDisabled(java.lang.String attributeName)
      Programmatically register an attribute for which data binding should not occur, not even for a subsequent @ModelAttribute declaration.
      void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)
      By default the content of the "default" model is used both during rendering and redirect scenarios.
      void setRedirectModel(ModelMap redirectModel)
      Provide a separate model instance to use in a redirect scenario.
      void setRedirectModelScenario(boolean redirectModelScenario)
      Whether the controller has returned a redirect instruction, e.g.
      void setRequestHandled(boolean requestHandled)
      Whether the request has been handled fully within the handler, e.g.
      void setStatus(HttpStatus status)
      Provide an HTTP status that will be passed on to with the ModelAndView used for view rendering purposes.
      void setView(java.lang.Object view)
      Set a View object to be used by the DispatcherServlet.
      void setViewName(java.lang.String viewName)
      Set a view name to be resolved by the DispatcherServlet via a ViewResolver.
      java.lang.String toString()
      Return diagnostic information.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ModelAndViewContainer

        public ModelAndViewContainer()
    • Method Detail

      • setIgnoreDefaultModelOnRedirect

        public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)
        By default the content of the "default" model is used both during rendering and redirect scenarios. Alternatively controller methods can declare an argument of type RedirectAttributes and use it to provide attributes to prepare the redirect URL.

        Setting this flag to true guarantees the "default" model is never used in a redirect scenario even if a RedirectAttributes argument is not declared. Setting it to false means the "default" model may be used in a redirect if the controller method doesn't declare a RedirectAttributes argument.

        The default setting is false.

      • setViewName

        public void setViewName(@Nullable
                                java.lang.String viewName)
        Set a view name to be resolved by the DispatcherServlet via a ViewResolver. Will override any pre-existing view name or View.
      • getViewName

        @Nullable
        public java.lang.String getViewName()
        Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if a View object is set.
      • setView

        public void setView(@Nullable
                            java.lang.Object view)
        Set a View object to be used by the DispatcherServlet. Will override any pre-existing view name or View.
      • getView

        @Nullable
        public java.lang.Object getView()
        Return the View object, or null if we using a view name to be resolved by the DispatcherServlet via a ViewResolver.
      • isViewReference

        public boolean isViewReference()
        Whether the view is a view reference specified via a name to be resolved by the DispatcherServlet via a ViewResolver.
      • getModel

        public ModelMap getModel()
        Return the model to use -- either the "default" or the "redirect" model. The default model is used if redirectModelScenario=false or there is no redirect model (i.e. RedirectAttributes was not declared as a method argument) and ignoreDefaultModelOnRedirect=false.
      • getDefaultModel

        public ModelMap getDefaultModel()
        Return the "default" model created at instantiation.

        In general it is recommended to use getModel() instead which returns either the "default" model (template rendering) or the "redirect" model (redirect URL preparation). Use of this method may be needed for advanced cases when access to the "default" model is needed regardless, e.g. to save model attributes specified via @SessionAttributes.

        Returns:
        the default model (never null)
        Since:
        4.1.4
      • setRedirectModel

        public void setRedirectModel(ModelMap redirectModel)
        Provide a separate model instance to use in a redirect scenario.

        The provided additional model however is not used unless setRedirectModelScenario(boolean) gets set to true to signal an actual redirect scenario.

      • setRedirectModelScenario

        public void setRedirectModelScenario(boolean redirectModelScenario)
        Whether the controller has returned a redirect instruction, e.g. a "redirect:" prefixed view name, a RedirectView instance, etc.
      • setStatus

        public void setStatus(@Nullable
                              HttpStatus status)
        Provide an HTTP status that will be passed on to with the ModelAndView used for view rendering purposes.
        Since:
        4.3
      • getStatus

        @Nullable
        public HttpStatus getStatus()
        Return the configured HTTP status, if any.
        Since:
        4.3
      • setBindingDisabled

        public void setBindingDisabled(java.lang.String attributeName)
        Programmatically register an attribute for which data binding should not occur, not even for a subsequent @ModelAttribute declaration.
        Parameters:
        attributeName - the name of the attribute
        Since:
        4.3
      • isBindingDisabled

        public boolean isBindingDisabled(java.lang.String name)
        Whether binding is disabled for the given model attribute.
        Since:
        4.3
      • setBinding

        public void setBinding(java.lang.String attributeName,
                               boolean enabled)
        Register whether data binding should occur for a corresponding model attribute, corresponding to an @ModelAttribute(binding=true/false) declaration.

        Note: While this flag will be taken into account by isBindingDisabled(java.lang.String), a hard setBindingDisabled(java.lang.String) declaration will always override it.

        Parameters:
        attributeName - the name of the attribute
        Since:
        4.3.13
      • getSessionStatus

        public SessionStatus getSessionStatus()
        Return the SessionStatus instance to use that can be used to signal that session processing is complete.
      • setRequestHandled

        public void setRequestHandled(boolean requestHandled)
        Whether the request has been handled fully within the handler, e.g. @ResponseBody method, and therefore view resolution is not necessary. This flag can also be set when controller methods declare an argument of type ServletResponse or OutputStream).

        The default value is false.

      • isRequestHandled

        public boolean isRequestHandled()
        Whether the request has been handled fully within the handler.
      • addAttribute

        public ModelAndViewContainer addAttribute(java.lang.String name,
                                                  @Nullable
                                                  java.lang.Object value)
        Add the supplied attribute to the underlying model. A shortcut for getModel().addAttribute(String, Object).
      • addAttribute

        public ModelAndViewContainer addAttribute(java.lang.Object value)
        Add the supplied attribute to the underlying model. A shortcut for getModel().addAttribute(Object).
      • addAllAttributes

        public ModelAndViewContainer addAllAttributes(@Nullable
                                                      java.util.Map<java.lang.String,?> attributes)
        Copy all attributes to the underlying model. A shortcut for getModel().addAllAttributes(Map).
      • mergeAttributes

        public ModelAndViewContainer mergeAttributes(@Nullable
                                                     java.util.Map<java.lang.String,?> attributes)
        Copy attributes in the supplied Map with existing objects of the same name taking precedence (i.e. not getting replaced). A shortcut for getModel().mergeAttributes(Map<String, ?>).
      • removeAttributes

        public ModelAndViewContainer removeAttributes(@Nullable
                                                      java.util.Map<java.lang.String,?> attributes)
        Remove the given attributes from the model.
      • containsAttribute

        public boolean containsAttribute(java.lang.String name)
        Whether the underlying model contains the given attribute name. A shortcut for getModel().containsAttribute(String).
      • toString

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