Why do you care about how it comes into the form bean?

Usually the big deal is how it winds up in the business object and there are
tools for that. FormDef does a really nice job, especially if you have to
deal with international date formats.


-----Original Message-----
From: Mark Bennett [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 22, 2005 3:27 PM
To: Struts Users Mailing List
Subject: RE: java.util.Date vs java.sql.Timestamp

Thanks for the reply, but unless I can get it to work with java.util.Date I
will stick with the java.util.Timestamp because THIS DOES WORK implicitly
without having to use SimpleDateFormat or any try/catch blocks.

<html:hidden name="myBean" property="myRecord.myDate"/>      <!-- modify
with date picker tag -->

  public setMyDate(Timestamp myDate) {
    this.myDate = myDate;
  }
  public Timestamp getMyDate() {
    return this.myDate;
  }

Using this I can round round trip the date as Timestamp using only basic
getters and setters.  But I would PREFER it was java.util.Date which I can't
get to work.

Mark

-----Original Message-----
From: Ashish Kulkarni [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 22, 2005 2:59 PM
To: Struts Users Mailing List
Subject: Re: java.util.Date vs java.sql.Timestamp


Hi
I would read the property as a String and then use
SimpleDateFormat to convert it to time stamp, i am not
sure if this conversion is done automatically in bean
public setMyDate(String myDateString)
 {
//i dont remmember the date format
try
{
SimpleDateFormat format = new SimpleDateFormat();
java.sql.Timestamp myDate =
format.parse(myDateString);
this.myDate = myDate;
}
catch(Exception exc)
{
}

   }
--- Mark Bennett <[EMAIL PROTECTED]> wrote:

> How can I have struts put a java.util.Date object
> into a Bean?
>
> I have found that I can set a Timestamp object into
> a bean.  THIS DOES WORK
> (below).  However, if I change the type on the bean
> to java.util.Date then I
> get a stack trace (also below).  I've also tried
> different formatting like:
> value="Sat Jan 01 00:00:00 EST 2005".  Any hints?
> Thanks.
>
> Mark
>
>
> class MyBean {
>   private java.sql.Timestamp myDate;
>
>   public setMyDate(java.sql.Timestamp myDate) {
>       this.myDate = myDate;
>   }
> }
>
> <input type="hidden" name="myDate" value="2005-01-01
> 00:00:00.0">
>
>
>
>
>
> java.lang.IllegalArgumentException: argument type
> mismatch
>       at java.lang.reflect.Method.invoke(Native Method)
>       at
>
org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.j
> ava:1789)
>       at
>
org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.j
> ava:1684)
>       at
>
org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:17
> 13)
>       at
>
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
>       at
>
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
>       at
>
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
>       at
>
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.j
> ava:821)
>       at
>
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
>       at
>
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
>       at
>
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
>       at
>
javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>       at
>
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at
>
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
> :263)
>       at
>
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
> :200)
>       at
>
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
> ntext.java:2390)
>       at
>
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
> :1959)
>       at
>
weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
>       at
>
weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
>




__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to