What I do is add a method for formatting dates (formatDateTime()) to the
action base class.  The method can then use the users Locale and TimeZone to
construct a DateFormat object.

    public String formatDateTime(Date timestamp)
    {
        return getDateFormat().format(timestamp);
    }

In the jsp I then I can then format the date ('updated' in this case) like
this:

<s:property value="formatDateTime(updated)" />

If you already have a DateFormat object around you could create a method in
you action that takes both the Date and the DateFormat.

Note: Be careful storing DateFormat in the Session as DateFormat is not
synchronized so it can not used concurrently by multiple threads.


On Thu, Oct 15, 2009 at 4:03 PM, Christian Bockermann <ch...@dorf.de> wrote:

> Hi list!
>
> I want to display a date in a user-specified manner (struts2 web-app)
> Thus, there exists a form where users can specify date-format strings, I
> validate them
> and on another page, I want to use the date-tag to display the date in the
> choosen format.
>
> So I have a session-property "date-format", accessible with
>
>        <s:property value="#session.date-format" />
>
> and would like to use this format property, something like
>
>        <s:date name="date" format="#session.date-format" />
>
> Unfortunately the date-tag does not allow expressions in its 'format'
> attribute. Any
> way around? Or is this simply not the right way to solve such a thing?
>
> Best regards,
>
>   Chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

Reply via email to