You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom Bednarz <li...@bednarz.ch> on 2006/09/27 19:13:03 UTC
Form conversion problem String to Date
I have a form with a date input field. This field is NOT mandatory, this
means it can contain a value or be empty.
Whenever the user does NOT fill in this datefield I get the following
exception:
javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.commons.beanutils.ConversionException
org.apache.commons.beanutils.converters.SqlDateConverter.convert(SqlDateConverter.java:117)
org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:428)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1004)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
My form is defined as follows:
<form-bean name="vehicleForm" type="ch.smartsol.struts.form.VehicleForm"/>
and in Java:
public class VehicleForm extends ValidatorActionForm
{
...
private Date dateOfCommissioning = null;
...
}
OK, the form member is of type Java.sql.Date and the form sends a String.
Questions:
==========
- WHEN does the conversion from string to Date take place?
- How can I deal with empty strings in case the user does NOT fill in
this date field?
Many thanks for your help!
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Form conversion problem String to Date
Posted by Chris Pratt <th...@gmail.com>.
Change your mutator to accept a String and perform the conversion yourself.
Then you can check for null or empty string before you start the conversion.
(*Chris*)
On 9/27/06, Tom Bednarz <li...@bednarz.ch> wrote:
>
> I have a form with a date input field. This field is NOT mandatory, this
> means it can contain a value or be empty.
>
> Whenever the user does NOT fill in this datefield I get the following
> exception:
>
> javax.servlet.ServletException: BeanUtils.populate
> org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
> org.apache.struts.action.RequestProcessor.processPopulate(
> RequestProcessor.java:805)
> org.apache.struts.action.RequestProcessor.process(RequestProcessor.java
> :203)
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
> org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
> root cause
>
> org.apache.commons.beanutils.ConversionException
> org.apache.commons.beanutils.converters.SqlDateConverter.convert(
> SqlDateConverter.java:117)
> org.apache.commons.beanutils.ConvertUtilsBean.convert(
> ConvertUtilsBean.java:428)
> org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java
> :1004)
> org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java
> :811)
> org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
> org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
>
>
> My form is defined as follows:
>
> <form-bean name="vehicleForm" type="ch.smartsol.struts.form.VehicleForm"/>
>
> and in Java:
>
> public class VehicleForm extends ValidatorActionForm
> {
> ...
> private Date dateOfCommissioning = null;
> ...
> }
>
>
> OK, the form member is of type Java.sql.Date and the form sends a String.
>
> Questions:
> ==========
>
> - WHEN does the conversion from string to Date take place?
> - How can I deal with empty strings in case the user does NOT fill in
> this date field?
>
> Many thanks for your help!
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>