Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to format a date using the Struts tag <bean:write>

1,777 views
Skip to first unread message

Amy Smith

unread,
Jun 13, 2003, 5:55:27 PM6/13/03
to
OK, I give up.

How do I format a GregorianCalendar when writing a bean to HTML using
Struts taglibs? (1.1 release candidate)

endDate is a GregorianCalendar.

<logic:iterate id="opt" name="optionsForm" property="options">
<TR>
<TD><bean:write name="opt" property='leadTime' /></TD>
<TD><bean:write name="opt" property='increment' /></TD>
<TD><bean:write name="opt" property='endOption' /></TD>
<TD><bean:write name="opt" property='endDate' /></TD>
</TR>
</logic:iterate>

Thanks,
--Amy

Brock Heinz

unread,
Jun 14, 2003, 12:35:04 AM6/14/03
to
Hello Amy,

The best way to do this (in my previous experience) is within your
Action. Stuts works in this manner.

From your view component, you initiate an Action.

Within your Action you delegate to your business tier (likely passing
and receiving Serializable ValueObjects)

Your ValueObject is something that models your datastore. So within
your Action you should be using Struts (presentation tier specific)
resources to send back to your JSP. So.. instead of worrying about
how the tag operates with values that aren't Strings you should do the
following:

Take your the value object and convert it into an ActionForm
(ActionForms typically take the shape of Strings and possibly
Collections). So, your Date property should be converted to a String
in your Action and passed along to your JSP. In the past, my action
forms were typically always contained String properties and then a
collection or two *(probably something similar to your 'optionsForm')
that were comprised of my value objects. After the headaches of
clearly displaying my data in the JSP when it came to things such as
Dates, I have taken a new approach. Now the collections that reside
in my ActionForm are not comprised of ValueObjects, but are now
comprised of ActionForms. This takes a bit more work in the Action,
but pays off big time in the JSP. I'm sorry if this isn't all too
clear - let me know if I can help more.

Brock


amy_...@hermanmiller.com (Amy Smith) wrote in message news:<6cb3ad10.03061...@posting.google.com>...

Amy Smith

unread,
Jun 16, 2003, 1:28:00 PM6/16/03
to
Hmmm, so do the formatting in the Action. Then, if the date was to be
displayed differently on different pages, I would have to determine to
what jsp the ActionForm was being sent. ...Not what I would choose
to do first, but it would work.

Thanks Brock.

Is there anyone who knows how to format a Gregorian Calendar from a
jsp using Struts taglibs?

If it is not possible with a Struts tag, the alternatives, as I see
them are:
1. Format in the Action.
2. Traditional jsp coding
3. JSTL

I'd like to avoid installing JSTL on top of Struts as the only use I
have for it right now is date and number formatting. Our MVC is very
good and there is little need for processing inside the jsp. Of
course, if this is the best way to go...

Argh, something so simple. Whoever designed dates in java should be
lined up against the wall.... Oops, sorry.

bro...@hotmail.com (Brock Heinz) wrote in message news:<8c84c600.03061...@posting.google.com>...

ebrusse

unread,
Jun 30, 2003, 11:00:55 PM6/30/03
to
Hi Amy,
You may want to try using the new "formatKey" parameter in the struts
bean:write tag. The formatKey maps to a name/value pair that you
define in your ApplicationResources.properties file

for example:


<bean:write name="opt" property="endDate"

formatKey="display.date.format" />

ApplicationResources.properties
display.date.format=mm/dd/yyyy

I have used this successfully with Date objects, not sure about
GregorianCalendar, but give it a shot.

Amy Smith

unread,
Jul 14, 2003, 3:50:04 PM7/14/03
to
Just a note as followup. formatKey does not support
GregorianCalendar.

I ended up coding a custom tag. I added null checking with default
values and date formatting for GregorianCalendar.

Works fine.

Thanks all
Amy Smith.

ebr...@yahoo.com (ebrusse) wrote in message news:<86fd12b8.03063...@posting.google.com>...

0 new messages