Class DefaultViewElementBuilderContext
- All Implemented Interfaces:
ReadableAttributes
,WritableAttributes
,LocalizedTextResolver
,ViewElementBuilderContext
,org.springframework.core.AttributeAccessor
- Direct Known Subclasses:
IteratorViewElementBuilderContext
Standard implementation of a ViewElementBuilderContext
that optionally allows a parent set of attributes
to be provided. Attributes from the parent will be visible in the context, but attributes set on the builder
context directly will hide the same attributes from the parent. Hiding with a non-null value is possible, but
removing attributes entirely from the parent is not.
For example when creating a new context based on a Model
, all attributes from the model will be
available on the context. Additional attributes can be added to the context only and will not be available in the
original Model. Changes to the model should propagate to the model (depending on the model implementation).
Custom implementations can override AttributeOverridingSupport.setParent(ReadableAttributes)
to allow the parent to be set
after construction.
This implementation also registers some default attributes, like the WebResourceRegistry
,
see registerMissingDefaultAttributes(ViewElementBuilderContext)
DefaultViewElementBuilderContext(boolean)
for sub class implementations that do not want the default
attributes set.
When there is no web context, this implementation will use default fallback implementations for the public signature
methods of ViewElementBuilderContext
. Ensuring that the calls themselves will not result in NPEs being thrown.- Author:
- Arne Vandamme
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final WebAppLinkBuilder
static final org.springframework.context.MessageSource
static final LocalizedTextResolver
-
Constructor Summary
ModifierConstructorDescriptionprotected
DefaultViewElementBuilderContext
(boolean registerDefaultAttributes) DefaultViewElementBuilderContext
(Map<String, Object> parent) DefaultViewElementBuilderContext
(org.springframework.ui.Model parent) -
Method Summary
Modifier and TypeMethodDescriptionWill build a link using theWebAppLinkBuilder
attribute that is present on this context.getMessage
(String code) Try to resolve the message.getMessage
(String code, Object[] args) Try to resolve the message.getMessage
(String code, Object[] args, String defaultMessage) Try to resolve the message.getMessage
(String code, Object[] args, String defaultMessage, Locale locale) Try to resolve the message.getMessage
(String code, Object[] args, Locale locale) Try to resolve the message.getMessage
(String code, String defaultMessage) Try to resolve the message.getMessage
(String code, String defaultMessage, Locale locale) Try to resolve the message.getMessage
(String code, Locale locale) Try to resolve the message.org.springframework.context.MessageSource
static void
registerMissingDefaultAttributes
(ViewElementBuilderContext builderContext) Registers default attributes in the builder context if they are not yet present.resolveText
(String text) Localize the text using theLocale
attached to the current thread.resolveText
(String text, String defaultValue) Localize the text using theLocale
attached to the current thread.resolveText
(String text, String defaultValue, Locale locale) Localize the text using theLocale
specified.resolveText
(String text, Locale locale) Localize the text using theLocale
specified.void
setLocalizedTextResolver
(LocalizedTextResolver textResolver) Set theLocalizedTextResolver
to use in this builder context.void
setMessageSource
(org.springframework.context.MessageSource messageSource) Set theMessageSource
that should be used in this builder context.void
setWebAppLinkBuilder
(WebAppLinkBuilder linkBuilder) Set theWebAppLinkBuilder
that should be used for calls tobuildLink(String)
.void
setWebResourceRegistry
(WebResourceRegistry webResourceRegistry) Set theWebResourceRegistry
for this builder context.Methods inherited from class com.foreach.across.core.support.AttributeOverridingSupport
attributeMap, attributeNames, findAttribute, findAttribute, findAttribute, getAttribute, getAttribute, getAttribute, getParent, hasAttribute, hasAttribute, setParent
Methods inherited from class com.foreach.across.core.support.AttributeSupport
removeAttribute, removeAttribute, setAttribute, setAttribute, setAttributes
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.core.AttributeAccessor
attributeNames, computeAttribute, getAttribute, hasAttribute, removeAttribute, setAttribute
Methods inherited from interface com.foreach.across.core.support.ReadableAttributes
attributeMap, attributeNames, getAttribute, getAttribute, getAttribute, hasAttribute, hasAttribute
Methods inherited from interface com.foreach.across.modules.web.ui.ViewElementBuilderContext
findAttribute, findAttribute, findAttribute, withAttributeOverride, withAttributeOverride
Methods inherited from interface com.foreach.across.core.support.WritableAttributes
removeAttribute, setAttribute, setAttributes
-
Field Details
-
FALLBACK_TEXT_RESOLVER
-
FALLBACK_LINK_BUILDER
-
FALLBACK_MESSAGE_SOURCE
public static final org.springframework.context.MessageSource FALLBACK_MESSAGE_SOURCE
-
-
Constructor Details
-
DefaultViewElementBuilderContext
public DefaultViewElementBuilderContext() -
DefaultViewElementBuilderContext
protected DefaultViewElementBuilderContext(boolean registerDefaultAttributes) -
DefaultViewElementBuilderContext
public DefaultViewElementBuilderContext(org.springframework.ui.Model parent) -
DefaultViewElementBuilderContext
-
DefaultViewElementBuilderContext
-
-
Method Details
-
setWebResourceRegistry
Set the
WebResourceRegistry
for this builder context. Builders can register additional resources if required for the view elements they generate. For example a datepicker control could register additional javascript.This method is an alias to calling
AttributeSupport.setAttribute(Class, Object)
withWebResourceRegistry.class
as attribute name, and the instance as value. The explicit method indicates that this attribute is not required but is expected.- Parameters:
webResourceRegistry
- instance
-
getWebResourceRegistry
-
setWebAppLinkBuilder
Set theWebAppLinkBuilder
that should be used for calls tobuildLink(String)
. By default the link builder attached to the current request would have been registered.- Parameters:
linkBuilder
- instance
-
getWebAppLinkBuilder
-
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource) Set theMessageSource
that should be used in this builder context.- Parameters:
messageSource
- to use
-
getMessageSource
public org.springframework.context.MessageSource getMessageSource() -
setLocalizedTextResolver
Set theLocalizedTextResolver
to use in this builder context.- Parameters:
textResolver
- to use
-
getLocalizedTextResolver
-
buildLink
Description copied from interface:ViewElementBuilderContext
Will build a link using theWebAppLinkBuilder
attribute that is present on this context. If none is present, the baseLink will remain unmodified.- Specified by:
buildLink
in interfaceViewElementBuilderContext
- Parameters:
baseLink
- to process- Returns:
- processed link
-
resolveText
Description copied from interface:LocalizedTextResolver
Localize the text using theLocale
attached to the current thread.- Specified by:
resolveText
in interfaceLocalizedTextResolver
- Parameters:
text
- to localize- Returns:
- localized text
-
resolveText
Description copied from interface:LocalizedTextResolver
Localize the text using theLocale
specified.- Specified by:
resolveText
in interfaceLocalizedTextResolver
- Parameters:
text
- to localizelocale
- to use- Returns:
- localized text
-
resolveText
Description copied from interface:LocalizedTextResolver
Localize the text using theLocale
attached to the current thread.- Specified by:
resolveText
in interfaceLocalizedTextResolver
- Parameters:
text
- to localizedefaultValue
- to return if resolved value isnull
- Returns:
- localized text
-
resolveText
Description copied from interface:LocalizedTextResolver
Localize the text using theLocale
specified.- Specified by:
resolveText
in interfaceLocalizedTextResolver
- Parameters:
text
- to localizedefaultValue
- to return if resolved value isnull
- Returns:
- localized text
-
getMessage
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return the message code no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- 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
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return default message if no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- 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
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return default message if no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- 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
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return default message if no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- Parameters:
code
- the code to lookup up, such as 'calculator.noRateSet'defaultMessage
- String to return if the lookup failslocale
- 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
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return message code if no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- 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), ornull
if none.- Returns:
- the resolved message if the lookup was successful; otherwise the message code
- See Also:
-
getMessage
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return message code if no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- 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), ornull
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
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return default message if no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- 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), ornull
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
Description copied from interface:ViewElementBuilderContext
Try to resolve the message. Return default message if no message was found.- Specified by:
getMessage
in interfaceViewElementBuilderContext
- 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), ornull
if none.defaultMessage
- String to return if the lookup failslocale
- 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:
-
registerMissingDefaultAttributes
Registers default attributes in the builder context if they are not yet present. If they are present - either directly or in the parent - they will be skipped.If there is a global
ViewElementBuilderContext
, the default attributes will be fetched from there. Otherwise request-bound values will be looked for:WebResourceRegistry
WebAppLinkBuilder
MessageSource
LocalizedTextResolver
: always created if none found, either using theMessageSource
or as as default
- Parameters:
builderContext
- to add the attributes to
-