You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ros <ro...@palivoda.id.lv> on 2007/02/20 12:31:40 UTC

s:select - format date

Hi!

Using Struts2 
<s:select id="reservationId" key="ticket.select"
list="purchase.event.reservations" listKey="id" 
                              listValue="dateTime+' '+price" />
has output:
<select name="ticket.select" id="reservationId">
    <option value="2">2009-09-27 00:00:00.0 0.01</option>
    <option value="1">2009-09-27 00:00:00.0 null</option>
</select>

How to set dateTime (java.util.Date) format? (e.g. to show only date)
How hide null values, if price is null?

Thanks!
-- 
View this message in context: http://www.nabble.com/s%3Aselect---format-date-tf3259859.html#a9060019
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: select - format date

Posted by Richard Yee <ry...@cruzio.com>.
Don't forget that DateFormat and any of its subclasses (ie
SimpleDateFormat) are NOT thread-safe. This means that you can't create
a static class instance of a SimpleDateFormat object that can be used by
different threads without creating a threading issue. If you need to use
a date formatter, check out the FastDateFormat class in the Jakarta
Commons Lang library or better yet, look at the Joda Time library at
SourceForge.

-Richard


Shuai Zheng wrote:
> You can try this:
>
> 1, try to get a SimpleDateFormat instance from action or stack
> 2, use the OGNL syntax to format it:
>
> <s:textfield required="true" label="出生日期"
> value="%{dateFormater.format(
> patient.dateOfBirth)}" />
>
> This works for my case.
>
> But I feel maybe it does not work for all the tags. You can try this
> approach.
>
> Regards,
>
> Zheng Shuai
>
> On 2/20/07, Bruno Melloni < Bruno.Melloni@wnco.com> wrote:
>>
>> There probably is a better "struts" way of doing this, but here is one
>> way that gets the job done:
>>
>> - Use a list of string-formatted datetimes. Format the dates before
>> putting them on the list.
>>
>> - For formatting, review the classes java.util.Date, java.util.Calendar,
>> java.text.DateFormat , java.text.SimpleDateFormat. Use appropriately.
>>
>> B.
>>
>> -----Original Message-----
>> From: ros [mailto:ros@palivoda.id.lv]
>> Sent: Tuesday, February 20, 2007 5:32 AM
>> To: user@struts.apache.org
>> Subject: s:select - format date
>>
>>
>> Hi!
>>
>> Using Struts2
>> <s:select id="reservationId" key="ticket.select"
>> list=" purchase.event.reservations" listKey="id"
>> listValue="dateTime+' '+price" /> has
>> output:
>> <select name="ticket.select" id="reservationId">
>> <option value="2">2009-09-27 00:00:00.0 0.01</option>
>> <option value="1">2009-09-27 00:00:00.0 null</option> </select>
>>
>> How to set dateTime (java.util.Date ) format? (e.g. to show only date)
>> How hide null values, if price is null?
>>
>> Thanks!
>> -- 
>> View this message in context:
>> http://www.nabble.com/s%3Aselect---format-date-tf3259859.html#a9060019
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>>
>


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


Re: select - format date

Posted by Shuai Zheng <zh...@gmail.com>.
You can try this:

1, try to get a SimpleDateFormat instance from action or stack
2, use the OGNL syntax to format it:

<s:textfield required="true" label="出生日期" value="%{dateFormater.format(
patient.dateOfBirth)}" />

This works for my case.

But I feel maybe it does not work for all the tags. You can try this
approach.

Regards,

Zheng Shuai

On 2/20/07, Bruno Melloni < Bruno.Melloni@wnco.com> wrote:
>
> There probably is a better "struts" way of doing this, but here is one
> way that gets the job done:
>
> - Use a list of string-formatted datetimes.  Format the dates before
> putting them on the list.
>
> - For formatting, review the classes java.util.Date, java.util.Calendar,
> java.text.DateFormat , java.text.SimpleDateFormat.  Use appropriately.
>
> B.
>
> -----Original Message-----
> From: ros [mailto:ros@palivoda.id.lv]
> Sent: Tuesday, February 20, 2007 5:32 AM
> To: user@struts.apache.org
> Subject: s:select - format date
>
>
> Hi!
>
> Using Struts2
> <s:select id="reservationId" key="ticket.select"
> list=" purchase.event.reservations" listKey="id"
>                               listValue="dateTime+' '+price" /> has
> output:
> <select name="ticket.select" id="reservationId">
>     <option value="2">2009-09-27 00:00:00.0 0.01</option>
>     <option value="1">2009-09-27 00:00:00.0 null</option> </select>
>
> How to set dateTime (java.util.Date ) format? (e.g. to show only date)
> How hide null values, if price is null?
>
> Thanks!
> --
> View this message in context:
> http://www.nabble.com/s%3Aselect---format-date-tf3259859.html#a9060019
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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: select - format date

Posted by ros <ro...@palivoda.id.lv>.
Found nothing better than:
listValue="dateTime.toString().substring(0, 16)+' - '+((sector == null) ? ''
: sector +' - ')"


Bruno Melloni-2 wrote:
> 
> There probably is a better "struts" way of doing this, but here is one
> way that gets the job done:
> 
> - Use a list of string-formatted datetimes.  Format the dates before
> putting them on the list.
> 
> - For formatting, review the classes java.util.Date, java.util.Calendar,
> java.text.DateFormat, java.text.SimpleDateFormat.  Use appropriately.
> 
> B.
> 
> -----Original Message-----
> From: ros [mailto:ros@palivoda.id.lv] 
> Sent: Tuesday, February 20, 2007 5:32 AM
> To: user@struts.apache.org
> Subject: s:select - format date
> 
> 
> Hi!
> 
> Using Struts2
> <s:select id="reservationId" key="ticket.select"
> list="purchase.event.reservations" listKey="id" 
>                               listValue="dateTime+' '+price" /> has
> output:
> <select name="ticket.select" id="reservationId">
>     <option value="2">2009-09-27 00:00:00.0 0.01</option>
>     <option value="1">2009-09-27 00:00:00.0 null</option> </select>
> 
> How to set dateTime (java.util.Date) format? (e.g. to show only date)
> How hide null values, if price is null?
> 
> Thanks!
> --
> View this message in context:
> http://www.nabble.com/s%3Aselect---format-date-tf3259859.html#a9060019
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/s%3Aselect---format-date-tf3259859.html#a9065033
Sent from the Struts - User mailing list archive at Nabble.com.


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


RE: select - format date

Posted by Bruno Melloni <Br...@wnco.com>.
There probably is a better "struts" way of doing this, but here is one
way that gets the job done:

- Use a list of string-formatted datetimes.  Format the dates before
putting them on the list.

- For formatting, review the classes java.util.Date, java.util.Calendar,
java.text.DateFormat, java.text.SimpleDateFormat.  Use appropriately.

B.

-----Original Message-----
From: ros [mailto:ros@palivoda.id.lv] 
Sent: Tuesday, February 20, 2007 5:32 AM
To: user@struts.apache.org
Subject: s:select - format date


Hi!

Using Struts2
<s:select id="reservationId" key="ticket.select"
list="purchase.event.reservations" listKey="id" 
                              listValue="dateTime+' '+price" /> has
output:
<select name="ticket.select" id="reservationId">
    <option value="2">2009-09-27 00:00:00.0 0.01</option>
    <option value="1">2009-09-27 00:00:00.0 null</option> </select>

How to set dateTime (java.util.Date) format? (e.g. to show only date)
How hide null values, if price is null?

Thanks!
--
View this message in context:
http://www.nabble.com/s%3Aselect---format-date-tf3259859.html#a9060019
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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