And I was looking more on this question and seems that keypoint of this that when I use "format" property DecimalFormat applyPattern(String pattern) method is called, and when "formatKey" property is used then applyLocalizedPattern(String pattern) method is called.

So seems that in resource file pattern must be in a "localized notation". So I don't understand why struts developers used this method, while applyPattern(String pattern) is working just fine. With this method struts users don't have to have patterns in "localized notation" (btw where to find these notations for locales?). And therefore struts users can have one common for example "###,###.00" pattern in a resource file and all numbers will be correctly formatted to visitor's locale. That makes code more portable and you can do change in one file rather than changing in each jsp...


Ilja S. wrote:
Hi
Thanks for reply but I'm still confused
What you mean "expected behavior"? In link to bugzilla you provided this is considered as a bug and it says it is fixed in Struts 1.2 family.
I'm using 1.2.9
As I understood this tag should format according to current locale.
All I want that numbers were formatted for users, and I don't want do this in business layer or in ActionForm. And seems that "format" property of <bean:write> is working correct while "formatKey" is not, even if I have resource file for other non-"en" locale.

So if this is expected behavior and NOT a bug, how then use this tag?

Thanks in advance

Christopher Goldman wrote:
On Fri, 2006-09-22 at 17:30 +0300, Ilja S. wrote:
Hello
Could you please explain why i get "JspException: Wrong format string: '###,###.00' " when I use <bean:write formatKey="global.format"> when other then "EN" locale is in user's session?

At the same time if use "format" tag <bean:write format="###,###.00"> then no matter what locale is in session it is working fine AND do format according to locale

Thanks in advance

Ilja,

Tere!

This is the expected behavior.  I'm not sure what version of Struts
you're using, but you can check out the source for the (1.x)
<bean:write> tag here:

http://svn.apache.org/viewvc/struts/struts1/trunk/taglib/src/main/java/org/apache/struts/taglib/bean/WriteTag.java?view=markup

The relevant part is from lines 330 to 348 (indenting modified):

if (formatString != null) {
  try {
    format = NumberFormat.getNumberInstance(locale);

    if (formatStrFromResources) {
      ((DecimalFormat) format).applyLocalizedPattern(
        formatString);
    } else {
      ((DecimalFormat) format).applyPattern(formatString);
    }
  } catch (IllegalArgumentException e) {
    JspException ex =
      new JspException(messages.getMessage(
          "write.format", formatString));

    TagUtils.getInstance().saveException(pageContext, ex);
    throw ex;
  }
}

There seems to be some discussion of this in the Struts JIRA system:

http://issues.apache.org/struts/browse/STR-1865?page=all

See Ted Husted's comments.  Of course, he's talking about the date (not
number) formatting, but it only serves to highlight the distinction
between the handling of the two types.  Note that if you look at the
code immediately following what is quoted here, you'll see that the
SimpleDateFormat constructor is *always* passed the locale.

I found all this stuff by Googling various combinations of "WriteTag",
".applyLocalizedPattern", and "IllegalArgumentException"

Hea õnn!

Chris





--
*************************************
Best Regards
Ilja


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to