Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

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

1.774 weergaven
Naar het eerste ongelezen bericht

Amy Smith

ongelezen,
13 jun 2003, 17:55:2713-06-2003
aan
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

ongelezen,
14 jun 2003, 00:35:0414-06-2003
aan
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

ongelezen,
16 jun 2003, 13:28:0016-06-2003
aan
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

ongelezen,
30 jun 2003, 23:00:5530-06-2003
aan
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

ongelezen,
14 jul 2003, 15:50:0414-07-2003
aan
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 nieuwe berichten