You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian Styles <gi...@hotmail.com> on 2004/01/08 14:43:21 UTC

Re: format tag in bean:write - was :RE: Handling Missing Message Key

Thanks Kris,

you've been a great help. Is there any example of default formats for all 
the types I might need that I can just copy into the resource bundle?


>From: Kris Schneider <kr...@dotech.com>
>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>To: Struts Users Mailing List <st...@jakarta.apache.org>
>Subject: Re: format tag in bean:write  - was :RE: Handling Missing Message 
>Key
>Date: Thu,  8 Jan 2004 08:35:14 -0500
>
>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.
>
>Quoting Brian Styles <gi...@hotmail.com>:
>
> > Ah, ha! I am an idiot. I think this has to do with the format tag in
> > bean:write. Could someone tell me how to set this up?
> >
> > I think you can put the formats into the application properties file,
> > correct?
> > Does someone have an example of what to put in?
> > thanks,
> > Brian
> >
> >
> > >From: "Brian Styles" <gi...@hotmail.com>
> > >Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > >To: struts-user@jakarta.apache.org
> > >Subject: RE: Handling Missing Message Key
> > >Date: Thu, 08 Jan 2004 13:11:38 +0000
> > >
> > >
> > >Thank you very much to Daniel and Kris for their help on this.
> > >Definately, extending the PropertyMessageResources and
> > >PropertyMessageResources factory is the way to go.
> > >
> > >Unfortunately, I've changed this and come up against a really nasty 
>error
> > >that I didn't have before!
> > >
> > >If anyone can help me I'd be eternally grateful!
> > >
> > >it seems that once I use my own ProperyMessageResources it affects the 
>way
> >
> > >the bean:write tag works!
> > >
> > >I have some fields that are stored in the database as Integers and when 
>I
> > >write them out with bean:write the string "int" gets prepended to 
>them!!!!
> >
> > >This didn't happen before.
> > >
> > >Disaster! anyone got any clue how to stop this
> > >
> > >thanks very much again,
> > >Brian
> > >
> > >>From: "Daniel Lipofsky" <da...@bricsnet.com>
> > >>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > >>To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > >>Subject: RE: Handling Missing Message Key
> > >>Date: Wed, 7 Jan 2004 17:43:57 -0800
> > >>
> > >>
> > >>I would suggest you extend PropertyMessageResources.
> > >>Overide constructor so that returnNull=true always.
> > >>Override getMessage to call super.getMessage(),
> > >>check for null, if null return key.
> > >>Very simple.  You probably have to extend the factory too.
> > >>- Dan
> > >>
> > >> > -----Original Message-----
> > >> > From: Brian Styles [mailto:givemeadamnusername@hotmail.com]
> > >> > Sent: Wednesday, January 07, 2004 1:18 PM
> > >> > To: struts-user@jakarta.apache.org
> > >> > Subject: Re: Handling Missing Message Key
> > >> >
> > >> >
> > >> >
> > >> > Thanks for the reply Kris,
> > >> >
> > >> > I think that setting the null property to true is probably
> > >> > the way to go.
> > >> > I even found an exactly similar thread as what I want to do
> > >> > from this June.
> > >> > Unfortunately there seems to be no definate answer.
> > >> >
> > >> > http://www.mail-archive.com/struts-user@jakarta.apache.org/msg
> > >> > 69627.html
> > >> >
> > >> > Anyone have any idea how to get rid of the "???"s
> > >> >
> > >> >
> > >> > >From: Kris Schneider <kr...@dotech.com>
> > >> > >Reply-To: "Struts Users Mailing List"
> > >> > <st...@jakarta.apache.org>
> > >> > >To: Struts Users Mailing List <st...@jakarta.apache.org>
> > >> > >Subject: Re: Handling Missing Message Key
> > >> > >Date: Wed,  7 Jan 2004 15:16:11 -0500
> > >> > >
> > >> > >Pretty sure you'd have to handle that yourself. It's
> > >> > probably cleaner to do
> > >> > >it
> > >> > >in an action.
> > >> > >
> > >> > >Action class:
> > >> > >
> > >> > >String dbProp = ...;
> > >> > >MessageResources messages = getResources(request);
> > >> > >String message = dpProp;
> > >> > >if (messages.isPresent(dbProp)) {
> > >> > >   message = messages.getMessage(dbProp);
> > >> > >}
> > >> > >request.setAttribute("message", message);
> > >> > >
> > >> > >JSP:
> > >> > >
> > >> > ><bean:write name="message"/>
> > >> > >
> > >> > >Or I suppose you could write your own tag...
> > >> > >
> > >> > >Quoting Brian Styles <gi...@hotmail.com>:
> > >> > >
> > >> > > > Hi all,
> > >> > > >
> > >> > > > I'm using the i8ln features in the struts bean tag library
> > >> > > >
> > >> > > > I populate a form bean with info from the database, and
> > >> > this info acts
> > >> > >as
> > >> > > > the key in a resource bundle so that I can add a
> > >> > international versions
> > >> > > > using
> > >> > > >
> > >> > > > <bean:message name="form" property="database_property"/>
> > >> > > >
> > >> > > > however, I would very much like the actual underlying
> > >> > property to be
> > >> > >written
> > >> > > >
> > >> > > > out if the key doesn't exist in the resource bundle,
> > >> > rather than getting
> > >> > >the
> > >> > > >
> > >> > > > nasty missing message key exception. Is this possible?
> > >> > > >
> > >> > > > thanks very much,
> > >> > > > Brian
> > >> > >
> > >> > >--
> > >> > >Kris Schneider <ma...@dotech.com>
> > >> > >D.O.Tech       <http://www.dotech.com/>
>
>--
>Kris Schneider <ma...@dotech.com>
>D.O.Tech       <http://www.dotech.com/>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus


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


Re: format tag in bean:write - was :RE: Handling Missing Message Key

Posted by Kris Schneider <kr...@dotech.com>.
Not that I'm aware of. However, you can play around with the various factory
methods of NumberFormat and DateFormat to get what you want:

DecimalFormat decFormat = (DecimalFormat)NumberFormat.getInstance();
System.out.println(decFormat.toPattern());
SimpleDateFormat dateFormat = (SimpleDateFormat)DateFormat.getInstance();
System.out.println(dateFormat.toPattern());

Which, for my system, produces:

#,##0.###
M/d/yy h:mm a

Quoting Brian Styles <gi...@hotmail.com>:

> Thanks Kris,
> 
> you've been a great help. Is there any example of default formats for all 
> the types I might need that I can just copy into the resource bundle?
> 
> 
> >From: Kris Schneider <kr...@dotech.com>
> >Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> >To: Struts Users Mailing List <st...@jakarta.apache.org>
> >Subject: Re: format tag in bean:write  - was :RE: Handling Missing Message
> 
> >Key
> >Date: Thu,  8 Jan 2004 08:35:14 -0500
> >
> >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.
> >
> >Quoting Brian Styles <gi...@hotmail.com>:
> >
> > > Ah, ha! I am an idiot. I think this has to do with the format tag in
> > > bean:write. Could someone tell me how to set this up?
> > >
> > > I think you can put the formats into the application properties file,
> > > correct?
> > > Does someone have an example of what to put in?
> > > thanks,
> > > Brian
> > >
> > >
> > > >From: "Brian Styles" <gi...@hotmail.com>
> > > >Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > > >To: struts-user@jakarta.apache.org
> > > >Subject: RE: Handling Missing Message Key
> > > >Date: Thu, 08 Jan 2004 13:11:38 +0000
> > > >
> > > >
> > > >Thank you very much to Daniel and Kris for their help on this.
> > > >Definately, extending the PropertyMessageResources and
> > > >PropertyMessageResources factory is the way to go.
> > > >
> > > >Unfortunately, I've changed this and come up against a really nasty 
> >error
> > > >that I didn't have before!
> > > >
> > > >If anyone can help me I'd be eternally grateful!
> > > >
> > > >it seems that once I use my own ProperyMessageResources it affects the
> 
> >way
> > >
> > > >the bean:write tag works!
> > > >
> > > >I have some fields that are stored in the database as Integers and when
> 
> >I
> > > >write them out with bean:write the string "int" gets prepended to 
> >them!!!!
> > >
> > > >This didn't happen before.
> > > >
> > > >Disaster! anyone got any clue how to stop this
> > > >
> > > >thanks very much again,
> > > >Brian
> > > >
> > > >>From: "Daniel Lipofsky" <da...@bricsnet.com>
> > > >>Reply-To: "Struts Users Mailing List"
> <st...@jakarta.apache.org>
> > > >>To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > > >>Subject: RE: Handling Missing Message Key
> > > >>Date: Wed, 7 Jan 2004 17:43:57 -0800
> > > >>
> > > >>
> > > >>I would suggest you extend PropertyMessageResources.
> > > >>Overide constructor so that returnNull=true always.
> > > >>Override getMessage to call super.getMessage(),
> > > >>check for null, if null return key.
> > > >>Very simple.  You probably have to extend the factory too.
> > > >>- Dan
> > > >>
> > > >> > -----Original Message-----
> > > >> > From: Brian Styles [mailto:givemeadamnusername@hotmail.com]
> > > >> > Sent: Wednesday, January 07, 2004 1:18 PM
> > > >> > To: struts-user@jakarta.apache.org
> > > >> > Subject: Re: Handling Missing Message Key
> > > >> >
> > > >> >
> > > >> >
> > > >> > Thanks for the reply Kris,
> > > >> >
> > > >> > I think that setting the null property to true is probably
> > > >> > the way to go.
> > > >> > I even found an exactly similar thread as what I want to do
> > > >> > from this June.
> > > >> > Unfortunately there seems to be no definate answer.
> > > >> >
> > > >> > http://www.mail-archive.com/struts-user@jakarta.apache.org/msg
> > > >> > 69627.html
> > > >> >
> > > >> > Anyone have any idea how to get rid of the "???"s
> > > >> >
> > > >> >
> > > >> > >From: Kris Schneider <kr...@dotech.com>
> > > >> > >Reply-To: "Struts Users Mailing List"
> > > >> > <st...@jakarta.apache.org>
> > > >> > >To: Struts Users Mailing List <st...@jakarta.apache.org>
> > > >> > >Subject: Re: Handling Missing Message Key
> > > >> > >Date: Wed,  7 Jan 2004 15:16:11 -0500
> > > >> > >
> > > >> > >Pretty sure you'd have to handle that yourself. It's
> > > >> > probably cleaner to do
> > > >> > >it
> > > >> > >in an action.
> > > >> > >
> > > >> > >Action class:
> > > >> > >
> > > >> > >String dbProp = ...;
> > > >> > >MessageResources messages = getResources(request);
> > > >> > >String message = dpProp;
> > > >> > >if (messages.isPresent(dbProp)) {
> > > >> > >   message = messages.getMessage(dbProp);
> > > >> > >}
> > > >> > >request.setAttribute("message", message);
> > > >> > >
> > > >> > >JSP:
> > > >> > >
> > > >> > ><bean:write name="message"/>
> > > >> > >
> > > >> > >Or I suppose you could write your own tag...
> > > >> > >
> > > >> > >Quoting Brian Styles <gi...@hotmail.com>:
> > > >> > >
> > > >> > > > Hi all,
> > > >> > > >
> > > >> > > > I'm using the i8ln features in the struts bean tag library
> > > >> > > >
> > > >> > > > I populate a form bean with info from the database, and
> > > >> > this info acts
> > > >> > >as
> > > >> > > > the key in a resource bundle so that I can add a
> > > >> > international versions
> > > >> > > > using
> > > >> > > >
> > > >> > > > <bean:message name="form" property="database_property"/>
> > > >> > > >
> > > >> > > > however, I would very much like the actual underlying
> > > >> > property to be
> > > >> > >written
> > > >> > > >
> > > >> > > > out if the key doesn't exist in the resource bundle,
> > > >> > rather than getting
> > > >> > >the
> > > >> > > >
> > > >> > > > nasty missing message key exception. Is this possible?
> > > >> > > >
> > > >> > > > thanks very much,
> > > >> > > > Brian
> > > >> > >
> > > >> > >--
> > > >> > >Kris Schneider <ma...@dotech.com>
> > > >> > >D.O.Tech       <http://www.dotech.com/>
> >
> >--
> >Kris Schneider <ma...@dotech.com>
> >D.O.Tech       <http://www.dotech.com/>

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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