Announcement Announcement Module
No announcement yet.
How to use a Formatter on a String with the spring:eval tag? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use a Formatter on a String with the spring:eval tag?

    I ran into a small problem today when I wanted to show a String property using spring:eval tag. The property has a custom converter associated with it using the AnnotationFormatterFactory.

    When the property is rendered using a form:input tag everything works as expected and the formatted output is shown.
    If the same property is rendered using the spring:eval tag the original, unformatted, value is shown.

    This is caused by the convertTypedValue() method in the ExpressionUtils class determining that the expression value is already a String and will not using the TypeConverter. I can imagine that most of the time this is the desired behavior, but when formatting a string it causes a problem.

    Maybe the spring:eval tag should get another attribute to indicate that the conversionservice should be used even if the type is already a String?

  • #2
    I am running into the same issue. My custom formatter (declared in FormattingConversionServiceFactoryBean) is applied to fields on a form-backing bean, but in any other scenario where I place an object into a ModelMap and attempt to display it on my .jsp, the formatter is not applied.

    Does anyone have an approach that works?