Hi
I'm moving my project to Spring 3, and trying to use its resources extensively. Now I'm trying to set up Date and BigDecimal formatters. Using 2.5, I created an initBinder and registered a custom editor on every controller, and used <fmt> on every field on JSP. I really dislike that solution, is too much intrusive, IMHO.
I'm trying to keep it simple and flexible, but so far no good. I wish to use annotations configurations (like @DateTimeFormat on Date fields, setting properties as needed - usually "S-") to keep it flexible, but avoid repetition (repeating the format everywhere). Using this annotation, my command field is being incorrectly parsed and incorrectly displayed back on the interface. Guess this should be because I need to set a locale, so I tried setting a FixedLocaleResolver like this:
It didn't worked (need to inject it somewhere? I couldn't find it). Guess I could use a pattern for the annotation, but I prefer something simpler and more flexible if someday my app becomes multilanguage. What am I missing to make the annotation work as expected?Code:<bean id="localeResolver" class="org.springframework.web.servlet.i18n.FixedLocaleResolver"> <property name="defaultLocale" value="xx_YY"/> </bean>
Also, I noticed that using style="S-" is formatting the year as 2 digits, and I want 4 digits for all my dates system-wide. If in my locale the year is also 2 digit, can I tweak it to 4 digit somehow in a simple way?
Similarly, when dealing with numbers (BigDecimal), I'll want to parse and print numbers without grouping separator on input fields, despite the locale format probably including the separator, as I believe they may lead to confusion (some folks using grouping separator as digit separator).
So, can I do these tasks with standard Spring annotation, or maybe I'll need to create my own formatter annotations?
Thanks!


Reply With Quote


