You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Alves <da...@davidalves.net> on 2007/03/12 07:18:37 UTC
Print property of a property using bean:write?
Hi all,
I have a User object which has a Country object attached to it,
representing the country that the user is from. If I do
<bean:write name="user" property="country" />
then I get the output of Country.toString(). However, say I want to call
one of the other methods in country, like population. Is there an
elegant way to do this? Something like
<bean:write name="user" property="country.population" />
where it would be translated behind-the-scenes into
user.getCountry().getPopulation() If there's a way to do this with
Struts Beans or if there's another tag library that would do it, I'd
appreciate it if you could point me in the right direction. I want to
avoid the use of <% %> if possible. Thanks for your time!
Regards,
David Alves
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Print property of a property using bean:write?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Laurie,
Laurie Harper wrote:
> Without thinking about it very much, I would expect that one or other of
> these would work:
>
> <bean:write name="user" property="country.population" />
> <bean:write name="user.country" property="population" />
Regardless of the method of output, your code needs to both read and
write the date in the same format.
If the date will be shown to the user, formatting in their locale is
appropriate. If the date will not be shown, I always recommend ISO-8601
date formatting.
I have a similar situation in that I need to allow users to specify
their own date format preferences. I keep their formats in a Map in the
session, and I wrote a custom validator to validate dates against those
formats. My forms contain only Strings, so in the form handler action, I
use those same formats to create a new SimpleDateFormat object and parse
the date.
I find that non-String form fields often results in conversion problems
like this. They are difficult to debug, too, since the error messages
are usually something along the lines of "field 'foo' is invalid", but
you aren't sure why. Unless you hack the code, you'll never find out
what's going on. If you use Strings, you can always disable validation
and start printing things out in your actions to help you debug.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF9WIM9CaO5/Lv0PARAmMdAJ4lp3o4dbs/c3OGWwr57s/VNr1+NgCgqGmB
pWQ64zY+1t+Hw8DJghB7lAc=
=EqKm
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Re: Print property of a property using bean:write?
Posted by "Raghupathy, Gurumoorthy" <Gu...@nielsen.com>.
How about Struts nested tag library? If you want to use struts taglibs
only ...
Regards
Guru
------------------------------------------------------------------------
-----------
Gurumoorthy Raghupathy
Email : gurumoorthy.raghupathy@vnuinc.co.uk
Internal Extn : 2337
External Phone : 01483712337
Nielsen Book
3rd Floor Midas House
62 Goldsworth Road
Woking Surrey GU21 6LQ
Visit us at : http://www.nielsenbookdata.co.uk/
------------------------------------------------------------------------
-----------
-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
Sent: 12 March 2007 10:33
To: user@struts.apache.org
Subject: Re: Print property of a property using bean:write?
David Alves wrote:
> Hi all,
>
> I have a User object which has a Country object attached to it,
> representing the country that the user is from. If I do
>
> <bean:write name="user" property="country" />
>
> then I get the output of Country.toString(). However, say I want to
call
> one of the other methods in country, like population. Is there an
> elegant way to do this? Something like
>
> <bean:write name="user" property="country.population" />
>
> where it would be translated behind-the-scenes into
> user.getCountry().getPopulation() If there's a way to do this with
> Struts Beans or if there's another tag library that would do it, I'd
> appreciate it if you could point me in the right direction. I want to
> avoid the use of <% %> if possible. Thanks for your time!
Without thinking about it very much, I would expect that one or other of
these would work:
<bean:write name="user" property="country.population" />
<bean:write name="user.country" property="population" />
but failing that, JSTL would probably be the better choice:
${user.country.population}
No muss, no fuss. If you aren't familiar with JSTL, take an hour to
learn it.
L.
---------------------------------------------------------------------
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: Print property of a property using bean:write?
Posted by Laurie Harper <la...@holoweb.net>.
David Alves wrote:
> Hi all,
>
> I have a User object which has a Country object attached to it,
> representing the country that the user is from. If I do
>
> <bean:write name="user" property="country" />
>
> then I get the output of Country.toString(). However, say I want to call
> one of the other methods in country, like population. Is there an
> elegant way to do this? Something like
>
> <bean:write name="user" property="country.population" />
>
> where it would be translated behind-the-scenes into
> user.getCountry().getPopulation() If there's a way to do this with
> Struts Beans or if there's another tag library that would do it, I'd
> appreciate it if you could point me in the right direction. I want to
> avoid the use of <% %> if possible. Thanks for your time!
Without thinking about it very much, I would expect that one or other of
these would work:
<bean:write name="user" property="country.population" />
<bean:write name="user.country" property="population" />
but failing that, JSTL would probably be the better choice:
${user.country.population}
No muss, no fuss. If you aren't familiar with JSTL, take an hour to
learn it.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org