commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yujun Liang" <yujun.li...@acm.org>
Subject java.util.Date in Action Form Bean
Date Fri, 28 Oct 2005 04:31:44 GMT
Hello,

I am working on a project using Struts. Struts uses BeanUtil to populate Action Form Bean.
This is such a nice framework to work with, except, 

BeanUtil doesn't support java.util.Date conversion. But when I use java.sql.Timestamp, it
asks for the format of 
yyyy-mm-dd hh:mm:ss.fffffffff

Here is the exception when I enter other format,

    Caused by: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff

In a web application, it is not reasonable to ask user to input yyyy-mm-dd hh:mm:ss.fffffffff.

Also, it doesn't support Locale.

Do you have experience getting java.util.Date populated in a Java Bean inside a FormBean?


Thanks in advance.

Regards
Yujun Liang
yujun.liang@acm.org
(0408) 467 448

1. Form Bean Definition,
<form-bean name="myForm" type="org.apache.struts.validator.DynaValidatorForm">

<form-property name="mybean" type="com.mycompany.myproject.bean.MyBean"/>

</form-bean>

2. Java Bean,

package com.mycompany.myproject.bean;

import java.io.Serializable;

import java.sql.Timestamp;

import org.apache.commons.lang.builder.EqualsBuilder;

import org.apache.commons.lang.builder.HashCodeBuilder;

import org.apache.commons.lang.builder.ToStringBuilder;

public abstract class MyBean implements Serializable {

    private long interchangeId;

    private Timestamp creationTime;

    private String originatingChannel;

    public long getInterchangeId() {

        return this.interchangeId;

    }

    public void setInterchangeId(long interchangeId) {

        this.interchangeId = interchangeId;

    }

    public Timestamp getCreationTime() {

        return this.creationTime;

    }

    

    public void setCreationTime(Timestamp creationTime) {

        this.creationTime = creationTime;

    }


    public String getOriginatingChannel() {

        return this.originatingChannel;

    }

    public void setOriginatingChannel(String originatingChannel) {

        this.originatingChannel = originatingChannel;

    }

}

3. HTML Form

<input name="mybean.creationTime" type="text" size="30" maxlength="30" value="25/10/2005">
<input name="mybean.originatingChannel" type="text" size="40" maxlength="40" value="originating
channel1">
<input name="mybean.originatingChannelUserId" type="text" size="60" maxlength="60" value="originating_channel_userid1">

4. Exception.

[28/10/05 14:05:42:623 EST] 3f64a3f WebGroup E SRVE0026E: [Servlet Error]-[BeanUtils.populate]:
org.apache.commons.beanutils.ConversionException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff

at org.apache.commons.beanutils.converters.SqlTimestampConverter.convert(SqlTimestampConverter.java:117)

at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:428)

at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1004)

at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)

at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)

at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)

at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)

at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)

at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)

at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)

at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)

at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)

at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message