commons-user mailing list archives

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

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.

Yujun Liang
(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"/>


2. Java Bean,

package com.mycompany.myproject.bean;


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

at org.apache.commons.beanutils.ConvertUtilsBean.convert(

at org.apache.commons.beanutils.BeanUtilsBean.setProperty(

at org.apache.commons.beanutils.BeanUtilsBean.populate(

at org.apache.commons.beanutils.BeanUtils.populate(

at org.apache.struts.util.RequestUtils.populate(

at org.apache.struts.action.RequestProcessor.processPopulate(

at org.apache.struts.action.RequestProcessor.process(

at org.apache.struts.action.ActionServlet.process(

at org.apache.struts.action.ActionServlet.doPost(

at javax.servlet.http.HttpServlet.service(

at javax.servlet.http.HttpServlet.service(








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