At 2:25 PM -0500 2/22/05, Mark Bennett 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.

This is because the BeanUtils library *does* register a standard converter for java.sql.Timestamp (as well as java.sql.Time and java.sql.Date) but *does not* register a standard converter for java.util.Date.


This is because there is a single specified String format for the SQL classes, while there is no String format which BeanUtils could safely assume for converting java.util.Date to and from a String representation.

If you want to use java.util.Date as a property and have BeanUtils do conversions for you, you must register a Converter. See http://jakarta.apache.org/commons/beanutils/ for more information.

Joe


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]


--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Narrow minds are weapons made for mass destruction" -The Ex


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



Reply via email to