Interface ViewElementBuilderContext

All Superinterfaces:
org.springframework.core.AttributeAccessor, LocalizedTextResolver, ReadableAttributes, WritableAttributes
All Known Implementing Classes:
DefaultViewElementBuilderContext, IteratorViewElementBuilderContext

public interface ViewElementBuilderContext extends WritableAttributes, LocalizedTextResolver
  • Method Details

    • getMessage

      String getMessage(String code)
      Try to resolve the message. Return the message code no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      Returns:
      the resolved message if the lookup was successful, otherwise the code itself
      See Also:
    • getMessage

      String getMessage(String code, Locale locale)
      Try to resolve the message. Return default message if no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      locale - the Locale in which to do the lookup
      Returns:
      the resolved message if the lookup was successful; otherwise the code itself
      See Also:
    • getMessage

      String getMessage(String code, String defaultMessage)
      Try to resolve the message. Return default message if no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      defaultMessage - String to return if the lookup fails
      Returns:
      the resolved message if the lookup was successful; otherwise the default message passed as a parameter
      See Also:
    • getMessage

      String getMessage(String code, String defaultMessage, Locale locale)
      Try to resolve the message. Return default message if no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      defaultMessage - String to return if the lookup fails
      locale - the Locale in which to do the lookup
      Returns:
      the resolved message if the lookup was successful; otherwise the default message passed as a parameter
      See Also:
    • getMessage

      String getMessage(String code, Object[] args)
      Try to resolve the message. Return message code if no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      args - array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
      Returns:
      the resolved message if the lookup was successful; otherwise the message code
      See Also:
    • getMessage

      String getMessage(String code, Object[] args, Locale locale)
      Try to resolve the message. Return message code if no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      args - array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
      locale - the Locale in which to do the lookup
      Returns:
      the resolved message if the lookup was successful; otherwise the message code
      See Also:
    • getMessage

      String getMessage(String code, Object[] args, String defaultMessage)
      Try to resolve the message. Return default message if no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      args - array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
      defaultMessage - String to return if the lookup fails
      Returns:
      the resolved message if the lookup was successful; otherwise the default message passed as a parameter
      See Also:
    • getMessage

      String getMessage(String code, Object[] args, String defaultMessage, Locale locale)
      Try to resolve the message. Return default message if no message was found.
      Parameters:
      code - the code to lookup up, such as 'calculator.noRateSet'
      args - array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
      defaultMessage - String to return if the lookup fails
      locale - the Locale in which to do the lookup
      Returns:
      the resolved message if the lookup was successful; otherwise the default message passed as a parameter
      See Also:
    • buildLink

      String buildLink(String baseLink)
      Will build a link using the WebAppLinkBuilder attribute that is present on this context. If none is present, the baseLink will remain unmodified.
      Parameters:
      baseLink - to process
      Returns:
      processed link
    • findAttribute

      InheritedAttributeValue<Object> findAttribute(String attributeName)
      Find an attribute value in this builder context or any of its parents, in case of a hierarchy.
      Parameters:
      attributeName - name of the attribute
      Returns:
      attribute value information - never null
    • findAttribute

      <U> InheritedAttributeValue<U> findAttribute(Class<U> attributeType)
      Find an attribute value in this builder context or any of its parents, in case of a hierarchy.
      Parameters:
      attributeType - type of the attribute
      Returns:
      attribute value information - never null
    • findAttribute

      <U> InheritedAttributeValue<U> findAttribute(String attributeName, Class<U> attributeType)
      Find an attribute value in this builder context or any of its parents, in case of a hierarchy.
      Parameters:
      attributeName - name of the attribute
      attributeType - expected type of the attribute
      Returns:
      attribute value information - never null
    • withAttributeOverride

      default ScopedAttributesViewElementBuilderContext withAttributeOverride(String attributeName, Object attributeValue)
      Create a temporary Closeable scope for the current ViewElementBuilderContext in which the given attribute value is overridden with the specified value. Setting null as attribute value will "remove" the attribute.

      Once ScopedAttributesViewElementBuilderContext.close() is called, the original attribute values will be reset.

      WARNING: this does not create a new separate builder context, it effectively modified the current builder context as long as ScopedAttributesViewElementBuilderContext.close() is not called.

      Parameters:
      attributeName - name of the attribute to override
      attributeValue - value to override the attribute with
      Returns:
      builder context scope
    • withAttributeOverride

      default <Y> ScopedAttributesViewElementBuilderContext withAttributeOverride(Class<Y> attributeType, Y attributeValue)
      Create a temporary Closeable scope for the current ViewElementBuilderContext in which the given attribute value is overridden with the specified value. Setting null as attribute value will "remove" the attribute.

      Once ScopedAttributesViewElementBuilderContext.close() is called, the original attribute values will be reset.

      WARNING: this does not create a new separate builder context, it effectively modified the current builder context as long as ScopedAttributesViewElementBuilderContext.close() is not called.

      Parameters:
      attributeType - type of the attribute to override
      attributeValue - value to override the attribute with
      Returns:
      builder context scope
    • retrieveGlobalBuilderContext

      static Optional<ViewElementBuilderContext> retrieveGlobalBuilderContext()
      Fetches the global ViewElementBuilderContext. Can be bound to the local thread using ViewElementBuilderContextHolder or - lacking that - to the request attributes.
      Returns:
      optional buildercontext
      See Also: