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 Harland <ha...@yahoo.com> on 2008/04/17 09:38:50 UTC

s2: How do you format a date and use it as a param value in a s:url

I have an action with a List<Message> messages. The
Message class has a Date senddate. In my jsp I am
iterating over the messages and want to create a s:url
with a param of formatedDate but I want to set the
value as a formatted version of senddate. I am
presently adding a getFormattedDate method which is
using SimpleDateFormat("dd/MM/yyyy
hh:mm:ss").format(senddate) in the Message class but I
don't want the formatting to be done in the Message.
Is there a more elegant way of doing this in the jsp please?


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

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


Re: s2: How do you format a date and use it as a param value in a s:url

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
David Harland wrote:
> I have an action with a List<Message> messages. The
> Message class has a Date senddate. In my jsp I am
> iterating over the messages and want to create a s:url
> with a param of formatedDate but I want to set the
> value as a formatted version of senddate. I am
> presently adding a getFormattedDate method which is
> using SimpleDateFormat("dd/MM/yyyy
> hh:mm:ss").format(senddate) in the Message class but I
> don't want the formatting to be done in the Message.
> Is there a more elegant way of doing this in the jsp please?
>
>
>       _______________

This is a common question.  It's something like this:

<s:url href="....">
   <s:param name="theDate">
      <s:date name="date" format="dd/MM/yyyy"/>
   </s:param>
</s:url>


ie. that's an s:date tag within a s:param tag within an s:url tag.  The 
formatted date is the body of the param tag.

It becomes more complicated when you need a locale dependent date or 
date conversion.

Hope that helps,
Jeromy Evans

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