In general, the answer to most questions like this is to do the work in
the Action, and then place the result in a bean for easy display. You
can obtain a reference to the message resources in the Action, 

MessageResources resource = servlet.getResources();

and then use the Java text-handling classes 

http://java.sun.com/docs/books/tutorial/i18n/format/index.html

like you would in any conventional Java program. 

The outcome can then be passed to the page in a simple JavaBean and
output with bean:write. The strength of Struts is that the Action class
provides a gateway to the business tier and lets us write Java programs
like Java programs. 

-- Ted Husted, Husted dot Com, Fairport NY US
-- Developing Java Web Applications with Struts
-- Tel: +1 585 737-3463
-- Web: http://husted.com/about/services


Fabien Modoux wrote:
> 
> I am trying to use the Message tag to handle the display of plural vs.
> singular. I tried the following simple example but it does not work as
> ChoiceFormat requires a Number but MessageTag's argN are of type String.
> 
> > jsp:
> 
> <% for (int i = 0; i < 5; i++) { %>
> <bean:message key="test1" arg0="<%= String.valueOf(i) %>"/>
> <% } %>
> 
> > application resources:
> 
> test1=There {0,choice,0#are no files|1#is one file|2#are {0,number,integer}
> files}.
> 
> > error:
> 
> java.lang.IllegalArgumentException: Cannot format given Object as a Number
>         at java.text.NumberFormat.format(NumberFormat.java:209)
>         at java.text.Format.format(Format.java:121)
>         at java.text.MessageFormat.format(MessageFormat.java:742)
>         at java.text.MessageFormat.format(MessageFormat.java:491)
>         at java.text.Format.format(Format.java:121)
>         at
> org.apache.struts.util.MessageResources.getMessage(MessageResources.java:325
> )
>         at org.apache.struts.util.RequestUtils.message(RequestUtils.java:586)
>         at org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:239)
> 
> Has anyone found a workaround for this, or is there another way to do it?
> 
> Thanks in advance,
> 
> Fabien
> 
> ---------------------------------------------
> Fabien Modoux,
> Voicemate - http://www.voicemate.com
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

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

Reply via email to