You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kumar M <ku...@netscape.net> on 2004/03/11 16:45:10 UTC

bean:message format ssn

Hi all,

I am wondering if there is an easy way to format the ssnn. What I have 
is a String '123456789' but the users would like to see '123-45-6789'. 
Is there an easy way of doing this using bean:write or bean:message or 
any other tag?

Thanks!!


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: AW: AW: bean:message format ssn

Posted by Kumar M <ku...@netscape.net>.
Yup,  formatKey is pretty handy. We use it to format dates. But 
<bean:write> tag seems to do this only when converting from non-String 
data type to String datatype. What I have is a String '123456789'. One 
solution is to probably convert this to Integer and that will force it 
to use a number formatter.

But <bean:message> seems to convert String to String too. And therefore 
the curiosity!

Thanks!


a.solarik@gesig.at wrote:

>Ah, I guess I misunderstood your previous post. Maybe this will help you
>along?
>
><snip>
>Use the formatKey attribute if you want to pull it from message resources.
>Have
>a look at java.text.DecimalFormat for an explanation of formatting patterns
>for
>decimal numbers.
></snip>
>
>The above code came from http://www.junlu.com/msg/45833.html. I didn't even
>know that this was possible. Lets see if I need it some day!
>
>
>Andreas
>
>-----Ursprungliche Nachricht-----
>Von: Kumar M [mailto:kumarm54@netscape.net]
>Gesendet: Donnerstag, 11. Marz 2004 17:30
>An: Struts Users Mailing List
>Betreff: Re: AW: bean:message format ssn
>
>
>
>Thanks for your replies.
>
>There seems to be a way to format using <bean:message>. If you look at
>the following article from Ted Husted:
>
>http://www.jguru.com/faq/view.jsp?EID=915891
>
> From the article:
>
>"ordering.authorized.range.staff=Staff is only authorized to requisition
>supplies that cost less than ${0,number} USD"
>
>would convert argument 0 to the number format. Isn't that nice!
>
>I was wondering if there is anyway we could extend this for things like
>ssn. I am looking at the MessageFormat class and all but was wondering
>if some one has come across this already.
>
>Thanks!
>
>
>a.solarik@gesig.at wrote:
>
>  
>
>>Hi Kumar,
>>
>>when you look at the documentation for bean:write
>>(http://jakarta.apache.org/struts/userGuide/struts-bean.html#write) you can
>>find that it allows formating. Bean:message looks like it does not support
>>this feature - which kind of makes sense when you consider what its used
>>    
>>
>for
>  
>
>>(lookup of strings in the resources -> supporting parameterized
>>replacement).
>>
>>The format of the format string is something like
>>
>><snip>
>> -  <tr>
>> -   <td><%= pageContext.getAttribute("test7.value") %></td>
>> -    <td>[#,000.00] <bean:write name="test7.value"
>>format="#,000.00"/></td>
>> -    <td>[<bean:message key="format.pattern" />] <bean:write
>>name="test7.value"
>>formatKey="format.pattern"/></td>
>> -  </tr>
>></snip>
>>
>>The preceeding code came from
>>http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg20743.html
>>
>>Andreas
>>
>>-----Ursprungliche Nachricht-----
>>Von: Kumar M [mailto:kumarm54@netscape.net]
>>Gesendet: Donnerstag, 11. Marz 2004 16:45
>>An: Struts Users Mailing List
>>Betreff: bean:message format ssn
>>
>>
>>
>>Hi all,
>>
>>I am wondering if there is an easy way to format the ssnn. What I have
>>is a String '123456789' but the users would like to see '123-45-6789'.
>>Is there an easy way of doing this using bean:write or bean:message or
>>any other tag?
>>
>>Thanks!!
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>  
>

Formatting in message resources (was: bean:message format ssn)

Posted by Hubert Rabago <ja...@yahoo.com>.
Yes, the default MessageResources implementation uses the Java Format object,
so in some of my messages, I have:

my.msg.key=No was found for {0,date,yyyyMM}

Cool, ain't it?  Not sure a lot of people know about it.  So you won't have
to mess with source code when all you wanna do is change data formatting.
Problem is, the JSP tags can only accept string values, so my particular
example (date formatting) only works on messages created in my Action
objects, not in my JSPs.  I'm pretty sure it'll work for Strings, though.


--- Andreas Solarik <a....@gesig.at> wrote:
> Ah, I guess I misunderstood your previous post. Maybe this will help you
> along?
> 
> <snip>
> Use the formatKey attribute if you want to pull it from message resources.
> Have
> a look at java.text.DecimalFormat for an explanation of formatting patterns
> for
> decimal numbers.
> </snip>
> 
> The above code came from http://www.junlu.com/msg/45833.html. I didn't even
> know that this was possible. Lets see if I need it some day!
> 
> 
> Andreas
> 
> -----Ursprungliche Nachricht-----
> Von: Kumar M [mailto:kumarm54@netscape.net]
> Gesendet: Donnerstag, 11. Marz 2004 17:30
> An: Struts Users Mailing List
> Betreff: Re: AW: bean:message format ssn
> 
> 
> 
> Thanks for your replies.
> 
> There seems to be a way to format using <bean:message>. If you look at
> the following article from Ted Husted:
> 
> http://www.jguru.com/faq/view.jsp?EID=915891
> 
>  From the article:
> 
> "ordering.authorized.range.staff=Staff is only authorized to requisition
> supplies that cost less than ${0,number} USD"
> 
> would convert argument 0 to the number format. Isn't that nice!
> 
> I was wondering if there is anyway we could extend this for things like
> ssn. I am looking at the MessageFormat class and all but was wondering
> if some one has come across this already.
> 
> Thanks!
> 
> 
> a.solarik@gesig.at wrote:
> 
> >Hi Kumar,
> >
> >when you look at the documentation for bean:write
> >(http://jakarta.apache.org/struts/userGuide/struts-bean.html#write) you
> can
> >find that it allows formating. Bean:message looks like it does not support
> >this feature - which kind of makes sense when you consider what its used
> for
> >(lookup of strings in the resources -> supporting parameterized
> >replacement).
> >
> >The format of the format string is something like
> >
> ><snip>
> >  -  <tr>
> >  -   <td><%= pageContext.getAttribute("test7.value") %></td>
> >  -    <td>[#,000.00] <bean:write name="test7.value"
> >format="#,000.00"/></td>
> >  -    <td>[<bean:message key="format.pattern" />] <bean:write
> >name="test7.value"
> >formatKey="format.pattern"/></td>
> >  -  </tr>
> ></snip>
> >
> >The preceeding code came from
> >http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg20743.html
> >
> >Andreas
> >
> >-----Ursprungliche Nachricht-----
> >Von: Kumar M [mailto:kumarm54@netscape.net]
> >Gesendet: Donnerstag, 11. Marz 2004 16:45
> >An: Struts Users Mailing List
> >Betreff: bean:message format ssn
> >
> >
> >
> >Hi all,
> >
> >I am wondering if there is an easy way to format the ssnn. What I have
> >is a String '123456789' but the users would like to see '123-45-6789'.
> >Is there an easy way of doing this using bean:write or bean:message or
> >any other tag?
> >
> >Thanks!!
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


AW: AW: bean:message format ssn

Posted by Andreas Solarik <a....@gesig.at>.
Ah, I guess I misunderstood your previous post. Maybe this will help you
along?

<snip>
Use the formatKey attribute if you want to pull it from message resources.
Have
a look at java.text.DecimalFormat for an explanation of formatting patterns
for
decimal numbers.
</snip>

The above code came from http://www.junlu.com/msg/45833.html. I didn't even
know that this was possible. Lets see if I need it some day!


Andreas

-----Ursprungliche Nachricht-----
Von: Kumar M [mailto:kumarm54@netscape.net]
Gesendet: Donnerstag, 11. Marz 2004 17:30
An: Struts Users Mailing List
Betreff: Re: AW: bean:message format ssn



Thanks for your replies.

There seems to be a way to format using <bean:message>. If you look at
the following article from Ted Husted:

http://www.jguru.com/faq/view.jsp?EID=915891

 From the article:

"ordering.authorized.range.staff=Staff is only authorized to requisition
supplies that cost less than ${0,number} USD"

would convert argument 0 to the number format. Isn't that nice!

I was wondering if there is anyway we could extend this for things like
ssn. I am looking at the MessageFormat class and all but was wondering
if some one has come across this already.

Thanks!


a.solarik@gesig.at wrote:

>Hi Kumar,
>
>when you look at the documentation for bean:write
>(http://jakarta.apache.org/struts/userGuide/struts-bean.html#write) you can
>find that it allows formating. Bean:message looks like it does not support
>this feature - which kind of makes sense when you consider what its used
for
>(lookup of strings in the resources -> supporting parameterized
>replacement).
>
>The format of the format string is something like
>
><snip>
>  -  <tr>
>  -   <td><%= pageContext.getAttribute("test7.value") %></td>
>  -    <td>[#,000.00] <bean:write name="test7.value"
>format="#,000.00"/></td>
>  -    <td>[<bean:message key="format.pattern" />] <bean:write
>name="test7.value"
>formatKey="format.pattern"/></td>
>  -  </tr>
></snip>
>
>The preceeding code came from
>http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg20743.html
>
>Andreas
>
>-----Ursprungliche Nachricht-----
>Von: Kumar M [mailto:kumarm54@netscape.net]
>Gesendet: Donnerstag, 11. Marz 2004 16:45
>An: Struts Users Mailing List
>Betreff: bean:message format ssn
>
>
>
>Hi all,
>
>I am wondering if there is an easy way to format the ssnn. What I have
>is a String '123456789' but the users would like to see '123-45-6789'.
>Is there an easy way of doing this using bean:write or bean:message or
>any other tag?
>
>Thanks!!
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: AW: bean:message format ssn

Posted by Kumar M <ku...@netscape.net>.
Thanks for your replies.

There seems to be a way to format using <bean:message>. If you look at 
the following article from Ted Husted:

http://www.jguru.com/faq/view.jsp?EID=915891

 From the article:

"ordering.authorized.range.staff=Staff is only authorized to requisition 
supplies that cost less than ${0,number} USD"

would convert argument 0 to the number format. Isn't that nice!

I was wondering if there is anyway we could extend this for things like 
ssn. I am looking at the MessageFormat class and all but was wondering 
if some one has come across this already.

Thanks!


a.solarik@gesig.at wrote:

>Hi Kumar,
>
>when you look at the documentation for bean:write
>(http://jakarta.apache.org/struts/userGuide/struts-bean.html#write) you can
>find that it allows formating. Bean:message looks like it does not support
>this feature - which kind of makes sense when you consider what its used for
>(lookup of strings in the resources -> supporting parameterized
>replacement).
>
>The format of the format string is something like
>
><snip>
>  -  <tr>
>  -   <td><%= pageContext.getAttribute("test7.value") %></td>
>  -    <td>[#,000.00] <bean:write name="test7.value"
>format="#,000.00"/></td>
>  -    <td>[<bean:message key="format.pattern" />] <bean:write
>name="test7.value"
>formatKey="format.pattern"/></td>
>  -  </tr>
></snip>
>
>The preceeding code came from
>http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg20743.html
>
>Andreas
>
>-----Ursprungliche Nachricht-----
>Von: Kumar M [mailto:kumarm54@netscape.net]
>Gesendet: Donnerstag, 11. Marz 2004 16:45
>An: Struts Users Mailing List
>Betreff: bean:message format ssn
>
>
>
>Hi all,
>
>I am wondering if there is an easy way to format the ssnn. What I have
>is a String '123456789' but the users would like to see '123-45-6789'.
>Is there an easy way of doing this using bean:write or bean:message or
>any other tag?
>
>Thanks!!
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>  
>

AW: bean:message format ssn

Posted by Andreas Solarik <a....@gesig.at>.
Hi Kumar,

when you look at the documentation for bean:write
(http://jakarta.apache.org/struts/userGuide/struts-bean.html#write) you can
find that it allows formating. Bean:message looks like it does not support
this feature - which kind of makes sense when you consider what its used for
(lookup of strings in the resources -> supporting parameterized
replacement).

The format of the format string is something like

<snip>
  -  <tr>
  -   <td><%= pageContext.getAttribute("test7.value") %></td>
  -    <td>[#,000.00] <bean:write name="test7.value"
format="#,000.00"/></td>
  -    <td>[<bean:message key="format.pattern" />] <bean:write
name="test7.value"
formatKey="format.pattern"/></td>
  -  </tr>
</snip>

The preceeding code came from
http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg20743.html

Andreas

-----Ursprungliche Nachricht-----
Von: Kumar M [mailto:kumarm54@netscape.net]
Gesendet: Donnerstag, 11. Marz 2004 16:45
An: Struts Users Mailing List
Betreff: bean:message format ssn



Hi all,

I am wondering if there is an easy way to format the ssnn. What I have
is a String '123456789' but the users would like to see '123-45-6789'.
Is there an easy way of doing this using bean:write or bean:message or
any other tag?

Thanks!!


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org