Hi Richard,

Have a look at http://struts.apache.org/2.1.6/docs/type-conversion.html 
It says that "dates - uses the SHORT format for the Locale associated with the 
current request"

May be this will help. 

Thank you.
Regards,
Kishan.G
 
Senior Software Engineer.
www.spansystems.com




-----Original Message-----
From: Richard Sayre [mailto:richardsa...@gmail.com] 
Sent: Thursday, April 30, 2009 4:14 PM
To: Struts Users Mailing List
Subject: Re: Submitting a Date to an Action

Thank you.  I will give it a try.

On Thu, Apr 30, 2009 at 1:22 AM, Matt Jiang <matt.ji...@gmail.com> wrote:
> Hi
>
> It is nothing about date picker tag. You can have a Converter to convert
> String to Date and vice versa.
> Below is my implementation for your reference:
> (For DateUtil, please replace with yours)
>
> public class DateConverter extends StrutsTypeConverter {
>
>  private static final String PATTERN = DateUtil.PATTERN_YYYY_MM_DD;
>
> �...@override
>  /**
>   * Converts one or more String values to the specified class.
>   *
>   * @param context the action context
>   * @param values  the String values to be converted, such as those
> submitted from an HTML form
>   * @param toClass the class to convert to
>   * @return the converted object
>   */
>  public Object convertFromString(Map context, String[] values, Class
> toClass) {
>
>    Date returnObject = null;
>    String value = values[0];
>    if (value != null && !value.trim().equals("")) {
>      try {
>        returnObject = DateUtil.parseDate(value, PATTERN);
>      } catch (ParseException e) {
>        // Just to ignore the parse exception
>      }
>    }
>    return returnObject;
>  }
>
> �...@override
>  /**
>   * Converts the specified object to a String.
>   *
>   * @param context the action context
>   * @param o       the object to be converted
>   * @return the converted String
>   */
>  public String convertToString(Map context, Object o) {
>
>    Date date = (Date) o;
>    String formatedDate = DateUtil.dateFormater(date, PATTERN);
>    return formatedDate;
>  }
> }
>
>
>
> On Thu, Apr 30, 2009 at 1:19 AM, Richard Sayre <richardsa...@gmail.com>wrote:
>
>> I have an Action with a date attribute
>>
>> private Date myDate;
>>
>> public void setMyDate(Date myDate) {
>> this.myDate = myDate;
>> }
>>
>> I have a form that has a date picker (not the struts 2 date picker)
>> that populates a text field.  When I submitt the form to my action the
>> property does not get set because Struts 2 is looking for
>> setMyDate(String myDate).
>>
>> How do I tell Struts that the field is a Date?
>>
>>
>> Thank you,
>>
>> Rich
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>

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


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

Reply via email to