you could write a beanutils converter and plugin for struts config e.g. <plug-in className="com.your.domain.beanutils.plugins.ConvertersPlugIn"> <set-property property="sqlDateFormat" value="dd/MM/yyyy"/> <set-property property="sqlDateAllowNull" value="true"/> </plug-in>
Your plugin class should register converters for each type e.g. Converter converter = new SqlDateConverter(..., sqlDateFormat, sqlDateAllowNull) ConvertUtils.register(converter, java.util.Date.class); etc -----Original Message----- From: Tom Bednarz [mailto:[EMAIL PROTECTED] Sent: Thursday, 28 September 2006 3:13 AM To: Struts Users Mailing List Subject: 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(RequestProcess or.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(SqlDate Converter.java:117) org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.j ava:428) org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.jav a:1004) org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:8 11) 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ********************************************************************** This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. ********************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]