程序包 cn.taketoday.web

类 BindingContext

java.lang.Object
cn.taketoday.web.BindingContext
直接已知子类:
InitBinderBindingContext

public class BindingContext extends Object
Context to assist with binding request data onto Objects and provide access to a shared Model with controller-specific attributes.

Provides methods to create a WebDataBinder for a specific target, command Object to apply data binding and validation to, or without a target Object for simple type conversion from request values.

Container for the default model for the request.

从以下版本开始:
4.0 2022/4/8 23:40
作者:
Rossen Stoyanchev, Juergen Hoeller, Harry Yang
  • 字段详细资料

    • model

      private cn.taketoday.ui.ModelMap model
    • redirectModel

      @Nullable private RedirectModel redirectModel
    • noBinding

      @Nullable private Set<String> noBinding
    • bindingDisabled

      @Nullable private Set<String> bindingDisabled
    • sessionStatus

      @Nullable private SessionStatus sessionStatus
    • initializer

      @Nullable private final WebBindingInitializer initializer
    • modelAndView

      protected ModelAndView modelAndView
  • 构造器详细资料

    • BindingContext

      public BindingContext()
      Create a new BindingContext.
    • BindingContext

      public BindingContext(@Nullable WebBindingInitializer initializer)
      Create a new BindingContext with the given initializer.
      参数:
      initializer - the binding initializer to apply (may be null)
  • 方法详细资料

    • createBinder

      public WebDataBinder createBinder(RequestContext context, String objectName) throws Throwable
      Create a WebDataBinder without a target object for type conversion of request values to simple types.
      参数:
      context - the current exchange
      objectName - the name of the target object
      返回:
      the created data binder
      抛出:
      Throwable - if @InitBinder method invocation fails
    • createBinder

      public WebDataBinder createBinder(RequestContext request, @Nullable Object target, String objectName) throws Throwable
      Create a WebDataBinder to apply data binding and validation with on the target, command object.
      参数:
      request - the current request
      target - the object to create a data binder for
      objectName - the name of the target object
      返回:
      the created data binder
      抛出:
      Throwable - if @InitBinder method invocation fails
    • createBinder

      public WebDataBinder createBinder(RequestContext request, @Nullable Object target, String objectName, @Nullable cn.taketoday.core.ResolvableType targetType) throws Throwable
      Variant of createBinder(RequestContext, Object, String) with a ResolvableType for which the DataBinder is created. This may be used to construct the target, or otherwise provide more insight on how to initialize the binder.
      抛出:
      Throwable
    • createBinderInstance

      protected WebDataBinder createBinderInstance(@Nullable Object target, String objectName, RequestContext request) throws Exception
      Extension point to create the WebDataBinder instance. By default this is WebDataBinder.
      参数:
      target - the binding target or null for type conversion only
      objectName - the binding target object name
      request - the current request
      抛出:
      Exception - in case of invalid state or arguments
    • initBinder

      public void initBinder(WebDataBinder dataBinder, RequestContext request) throws Throwable
      Initialize the data binder instance for the given exchange.
      抛出:
      Throwable - if @InitBinder method invocation fails
    • getModelAndView

      public ModelAndView getModelAndView()
      Get a ModelAndView

      If there isn't a ModelAndView in this RequestContext, Create One

      返回:
      Returns ModelAndView
    • hasModelAndView

      public boolean hasModelAndView()
      从以下版本开始:
      3.0
    • hasModel

      public boolean hasModel()
      从以下版本开始:
      4.0
    • getModel

      public cn.taketoday.ui.ModelMap getModel()
      Return the default model.
    • updateModel

      public void updateModel(RequestContext request) throws Throwable
      Promote model attributes listed as @SessionAttributes to the session. Add BindingResult attributes where necessary.
      参数:
      request - the current request
      抛出:
      Throwable - if creating BindingResult attributes fails
    • initModel

      public void initModel(RequestContext request) throws Throwable
      Populate the model in the following order:
      1. Retrieve "known" session attributes listed as @SessionAttributes.
      2. Invoke @ModelAttribute methods
      3. Find @ModelAttribute method arguments also listed as @SessionAttributes and ensure they're present in the model raising an exception if necessary.
      参数:
      request - the current request
      抛出:
      Throwable - may arise from @ModelAttribute methods
    • getRedirectModel

      @Nullable public RedirectModel getRedirectModel()
    • setRedirectModel

      public void setRedirectModel(@Nullable RedirectModel redirectModel)
    • setBindingDisabled

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

      public boolean isBindingDisabled(String name)
      Whether binding is disabled for the given model attribute.
    • setBinding

      public void setBinding(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.

      参数:
      attributeName - the name of the attribute
    • getSessionStatus

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

      public boolean isSessionComplete()
      Return whether the current handler's session processing has been marked as complete.
    • addAttribute

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

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

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

      public BindingContext mergeAttributes(@Nullable Map<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 BindingContext removeAttributes(@Nullable Map<String,?> attributes)
      Remove the given attributes from the model.
    • containsAttribute

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

      public String toString()
      Return diagnostic information.
      覆盖:
      toString 在类中 Object