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
FieldsModifier and TypeFieldDescriptionstatic final WebAppLinkBuilderstatic final org.springframework.context.MessageSourcestatic final LocalizedTextResolver - 
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultViewElementBuilderContext(boolean registerDefaultAttributes) DefaultViewElementBuilderContext(Map<String, Object> parent) DefaultViewElementBuilderContext(org.springframework.ui.Model parent)  - 
Method Summary
Modifier and TypeMethodDescriptionWill build a link using theWebAppLinkBuilderattribute 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.MessageSourcestatic voidregisterMissingDefaultAttributes(ViewElementBuilderContext builderContext) Registers default attributes in the builder context if they are not yet present.resolveText(String text) Localize the text using theLocaleattached to the current thread.resolveText(String text, String defaultValue) Localize the text using theLocaleattached to the current thread.resolveText(String text, String defaultValue, Locale locale) Localize the text using theLocalespecified.resolveText(String text, Locale locale) Localize the text using theLocalespecified.voidsetLocalizedTextResolver(LocalizedTextResolver textResolver) Set theLocalizedTextResolverto use in this builder context.voidsetMessageSource(org.springframework.context.MessageSource messageSource) Set theMessageSourcethat should be used in this builder context.voidsetWebAppLinkBuilder(WebAppLinkBuilder linkBuilder) Set theWebAppLinkBuilderthat should be used for calls tobuildLink(String).voidsetWebResourceRegistry(WebResourceRegistry webResourceRegistry) Set theWebResourceRegistryfor this builder context.Methods inherited from class com.foreach.across.core.support.AttributeOverridingSupport
attributeMap, attributeNames, findAttribute, findAttribute, findAttribute, getAttribute, getAttribute, getAttribute, getParent, hasAttribute, hasAttribute, setParentMethods inherited from class com.foreach.across.core.support.AttributeSupport
removeAttribute, removeAttribute, setAttribute, setAttribute, setAttributesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.AttributeAccessor
attributeNames, computeAttribute, getAttribute, hasAttribute, removeAttribute, setAttributeMethods inherited from interface com.foreach.across.core.support.ReadableAttributes
attributeMap, attributeNames, getAttribute, getAttribute, getAttribute, hasAttribute, hasAttributeMethods inherited from interface com.foreach.across.modules.web.ui.ViewElementBuilderContext
findAttribute, findAttribute, findAttribute, withAttributeOverride, withAttributeOverrideMethods 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
WebResourceRegistryfor 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.classas 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 theWebAppLinkBuilderthat 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 theMessageSourcethat should be used in this builder context.- Parameters:
 messageSource- to use
 - 
getMessageSource
public org.springframework.context.MessageSource getMessageSource() - 
setLocalizedTextResolver
Set theLocalizedTextResolverto use in this builder context.- Parameters:
 textResolver- to use
 - 
getLocalizedTextResolver
 - 
buildLink
Description copied from interface:ViewElementBuilderContextWill build a link using theWebAppLinkBuilderattribute that is present on this context. If none is present, the baseLink will remain unmodified.- Specified by:
 buildLinkin interfaceViewElementBuilderContext- Parameters:
 baseLink- to process- Returns:
 - processed link
 
 - 
resolveText
Description copied from interface:LocalizedTextResolverLocalize the text using theLocaleattached to the current thread.- Specified by:
 resolveTextin interfaceLocalizedTextResolver- Parameters:
 text- to localize- Returns:
 - localized text
 
 - 
resolveText
Description copied from interface:LocalizedTextResolverLocalize the text using theLocalespecified.- Specified by:
 resolveTextin interfaceLocalizedTextResolver- Parameters:
 text- to localizelocale- to use- Returns:
 - localized text
 
 - 
resolveText
Description copied from interface:LocalizedTextResolverLocalize the text using theLocaleattached to the current thread.- Specified by:
 resolveTextin interfaceLocalizedTextResolver- Parameters:
 text- to localizedefaultValue- to return if resolved value isnull- Returns:
 - localized text
 
 - 
resolveText
Description copied from interface:LocalizedTextResolverLocalize the text using theLocalespecified.- Specified by:
 resolveTextin interfaceLocalizedTextResolver- Parameters:
 text- to localizedefaultValue- to return if resolved value isnull- Returns:
 - localized text
 
 - 
getMessage
Description copied from interface:ViewElementBuilderContextTry to resolve the message. Return the message code no message was found.- Specified by:
 getMessagein 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:ViewElementBuilderContextTry to resolve the message. Return default message if no message was found.- Specified by:
 getMessagein 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:ViewElementBuilderContextTry to resolve the message. Return default message if no message was found.- Specified by:
 getMessagein 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:ViewElementBuilderContextTry to resolve the message. Return default message if no message was found.- Specified by:
 getMessagein 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:ViewElementBuilderContextTry to resolve the message. Return message code if no message was found.- Specified by:
 getMessagein 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), ornullif none.- Returns:
 - the resolved message if the lookup was successful; otherwise the message code
 - See Also:
 
 - 
getMessage
Description copied from interface:ViewElementBuilderContextTry to resolve the message. Return message code if no message was found.- Specified by:
 getMessagein 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), ornullif 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:ViewElementBuilderContextTry to resolve the message. Return default message if no message was found.- Specified by:
 getMessagein 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), ornullif 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:ViewElementBuilderContextTry to resolve the message. Return default message if no message was found.- Specified by:
 getMessagein 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), ornullif 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:WebResourceRegistryWebAppLinkBuilderMessageSourceLocalizedTextResolver: always created if none found, either using theMessageSourceor as as default
- Parameters:
 builderContext- to add the attributes to
 
 -