You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sr...@wachovia.com on 2007/08/29 20:05:46 UTC

How format a string when it is Displayed?

Hi, 

I need help in formatting a String, when it is displayed.

Here is what i am doing:

<bean:write name="someObject" property="exampleSSN"/>

It is stored asa continous unformatted String an hence displayed as 
'XXXXXXXXX'. Now, I want my social security number to be displayed as 
(XXX) - XX - XXXX.

How can i acheive this in Struts, without actually using my own custom Tag 
libraries which do this formatting for me. If somebody can throw some 
pointers, it woould help the cause.



Re: How format a string when it is Displayed?

Posted by Josh Vickery <jo...@vickeryj.com>.
http://cwiki.apache.org/confluence/display/WW/text will do what you
need.  Take look at the example with resource property "format.money"
and note the link to
http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html
which has the info you need to build a format pattern.  You could also
do the same thing with JSTL if you prefer:
http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fmt/tld-summary.html

Josh

On 8/29/07, sriharsha.chevuru@wachovia.com
<sr...@wachovia.com> wrote:
> Hi,
>
> I need help in formatting a String, when it is displayed.
>
> Here is what i am doing:
>
> <bean:write name="someObject" property="exampleSSN"/>
>
> It is stored asa continous unformatted String an hence displayed as
> 'XXXXXXXXX'. Now, I want my social security number to be displayed as
> (XXX) - XX - XXXX.
>
> How can i acheive this in Struts, without actually using my own custom Tag
> libraries which do this formatting for me. If somebody can throw some
> pointers, it woould help the cause.
>
>
>

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


Re: How format a string when it is Displayed?

Posted by Josh Vickery <jo...@vickeryj.com>.
Oops, I missed that you are using Struts 1.  I believe that you can
use the format attribute of the bean:write tag:
http://struts.apache.org/1.1/userGuide/struts-bean.html#write to
specify a format string as described on:
http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html

Josh


On 8/30/07, vamsi <va...@gmail.com> wrote:
> I think we can't format a String using bean:write
> previously I searched for this but I didn't found any solution as it is not
> supporting any formatting for
> Strings.
> ----- Original Message -----
> From: <sr...@wachovia.com>
> To: <us...@struts.apache.org>
> Sent: Wednesday, August 29, 2007 11:35 PM
> Subject: How format a string when it is Displayed?
>
>
> > Hi,
> >
> > I need help in formatting a String, when it is displayed.
> >
> > Here is what i am doing:
> >
> > <bean:write name="someObject" property="exampleSSN"/>
> >
> > It is stored asa continous unformatted String an hence displayed as
> > 'XXXXXXXXX'. Now, I want my social security number to be displayed as
> > (XXX) - XX - XXXX.
> >
> > How can i acheive this in Struts, without actually using my own custom Tag
> > libraries which do this formatting for me. If somebody can throw some
> > pointers, it woould help the cause.
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Re: How format a string when it is Displayed?

Posted by vamsi <va...@gmail.com>.
I think we can't format a String using bean:write
previously I searched for this but I didn't found any solution as it is not 
supporting any formatting for
Strings.
----- Original Message ----- 
From: <sr...@wachovia.com>
To: <us...@struts.apache.org>
Sent: Wednesday, August 29, 2007 11:35 PM
Subject: How format a string when it is Displayed?


> Hi,
>
> I need help in formatting a String, when it is displayed.
>
> Here is what i am doing:
>
> <bean:write name="someObject" property="exampleSSN"/>
>
> It is stored asa continous unformatted String an hence displayed as
> 'XXXXXXXXX'. Now, I want my social security number to be displayed as
> (XXX) - XX - XXXX.
>
> How can i acheive this in Struts, without actually using my own custom Tag
> libraries which do this formatting for me. If somebody can throw some
> pointers, it woould help the cause.
>
>
> 


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