[ 
https://issues.apache.org/jira/browse/WICKET-1719?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Igor Vaynberg resolved WICKET-1719.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 1.4-M4
         Assignee: Igor Vaynberg

> StringResourceModel may fail to format numbers using MessageFormat
> ------------------------------------------------------------------
>
>                 Key: WICKET-1719
>                 URL: https://issues.apache.org/jira/browse/WICKET-1719
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.3.3
>            Reporter: Andrea Aime
>            Assignee: Igor Vaynberg
>             Fix For: 1.3.5, 1.4-M4
>
>
> StringResourceModel API seems to suggest it's possible to use it without a 
> Component reference using the following approach:
> {code}
> m = new StringResourceModel("key", null, new Model(...), new Object[] {p1, 
> p2, ...});
> m.setLocalizer(xxxApplication.get().getResourceSettings().getLocalizer());
> return m.toString()
> {code}
> Unfortunately the above will fail with an exception if the message uses the 
> MessageFormat approach and one of the parameters
> is a number, since the locale field in StringResourceModel won't be 
> initialized, and will then be passed as null to new MessageFormat(value, 
> locale) at line 514 of StringResourceFormat.
> I'm using the following crude workaround:
> {code}
> StringResourceModel rm = new StringResourceModel(key, null, model, params) {
>             @Override
>             public void setLocalizer(Localizer localizer) {
>                 super.setLocalizer(localizer);
>                 // crude hack to force into the StringResoruceLoader to grab 
> a locale,
>                 // which is needed to format numbers with the MessageFormat 
> approach
>                 load();
>             }
>         };
>         
> rm.setLocalizer(GeoServerApplication.get().getResourceSettings().getLocalizer());
>         return rm.getString();
> {code}
> but boy, this looks ugly... Creating a custom subclass that does locale 
> loading in the
> constructor would look better, but still quite ugly...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to