Class SpringMessageResolver

Object
org.thymeleaf.messageresolver.AbstractMessageResolver
org.thymeleaf.spring6.messageresolver.SpringMessageResolver
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware, org.thymeleaf.messageresolver.IMessageResolver

public class SpringMessageResolver extends org.thymeleaf.messageresolver.AbstractMessageResolver implements org.springframework.context.MessageSourceAware

Implementation of IMessageResolver that integrates the standard Spring way of resolving messages into Thymeleaf.

Template-based resolution is done by means of using the available Spring-configured MessageSource objects.

Origin-based resolution is done in exactly the same way as in StandardMessageResolver.

Since:
3.0.3
Author:
Daniel Fernández
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    createAbsentMessageRepresentation(org.thymeleaf.context.ITemplateContext context, Class<?> origin, String key, Object[] messageParameters)
     
    final org.springframework.context.MessageSource
    Returns the message source (MessageSource) to be used for message resolution.
    final boolean
    Returns whether an exception will be raised when a message cannot be resolved and an absent message representation (like ??key_locale??) would be returned instead.
    final String
    resolveMessage(org.thymeleaf.context.ITemplateContext context, Class<?> origin, String key, Object[] messageParameters)
     
    final void
    setFailOnMissingMessage(boolean failOnMissingMessage)
    Sets whether an exception will be raised when a message cannot be resolved and an absent message representation (like ??key_locale??) would be returned instead.
    final void
    setMessageSource(org.springframework.context.MessageSource messageSource)
    Sets the message source to be used for message resolution

    Methods inherited from class org.thymeleaf.messageresolver.AbstractMessageResolver

    getName, getOrder, setName, setOrder

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringMessageResolver

      public SpringMessageResolver()
  • Method Details

    • getMessageSource

      public final org.springframework.context.MessageSource getMessageSource()

      Returns the message source (MessageSource) to be used for message resolution.

      Returns:
      the message source
    • setMessageSource

      public final void setMessageSource(org.springframework.context.MessageSource messageSource)

      Sets the message source to be used for message resolution

      Specified by:
      setMessageSource in interface org.springframework.context.MessageSourceAware
      Parameters:
      messageSource - the message source
    • isFailOnMissingMessage

      public final boolean isFailOnMissingMessage()

      Returns whether an exception will be raised when a message cannot be resolved and an absent message representation (like ??key_locale??) would be returned instead. Default is false.

      Returns:
      whether missing messages raise an exception.
      Since:
      3.1.7
    • setFailOnMissingMessage

      public final void setFailOnMissingMessage(boolean failOnMissingMessage)

      Sets whether an exception will be raised when a message cannot be resolved and an absent message representation (like ??key_locale??) would be returned instead. Default is false.

      This applies to message expressions (#{...}) and to the #messages.msg(...) family of methods, but not to the #messages.msgOrNull(...) family, which will still return null for messages that cannot be resolved.

      Parameters:
      failOnMissingMessage - whether missing messages should raise an exception.
      Since:
      3.1.7
    • resolveMessage

      public final String resolveMessage(org.thymeleaf.context.ITemplateContext context, Class<?> origin, String key, Object[] messageParameters)
      Specified by:
      resolveMessage in interface org.thymeleaf.messageresolver.IMessageResolver
    • createAbsentMessageRepresentation

      public String createAbsentMessageRepresentation(org.thymeleaf.context.ITemplateContext context, Class<?> origin, String key, Object[] messageParameters)
      Specified by:
      createAbsentMessageRepresentation in interface org.thymeleaf.messageresolver.IMessageResolver