DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22703>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22703 date field pattern in struts form: inconsistency Summary: date field pattern in struts form: inconsistency Product: Struts Version: 1.1 Final Platform: Other URL: http://groups.google.com/groups?hl=en&lr=&ie=UTF- 8&oe=UTF- 8&selm=e2b70d9d.0308141020.6a7abac3%40posting.google.com OS/Version: Other Status: NEW Severity: Normal Priority: Other Component: Controller AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] If property of the ActionForm is defined as Date the following problems arise: 1. SqlDateLocaleConverter has to be used in order to set String -> Date conversion pattern: SqlDateLocaleConverter dateConverter = new SqlDateLocaleConverter(Locale.getDefault(), DEFAULT_DATE_PATTERN); dateConverter.setLenient(false); ConvertUtils.register(dateConverter, java.sql.Date.class); That however takes care ONLY of the String -> Date. 2. In order to successfully convert from Date -> String bean:write tag have to be used instead of html:text. There is a property 'format' in bean:write. Unfortunately, html:text tag does not currently support 'format' attribute. I believe that the following code from BaseFieldTag.doStartTag() is responsible for that: if (value != null) { results.append(ResponseUtils.filter(value)); } else if (redisplay || !"password".equals(type)) { Object value = RequestUtils.lookup(pageContext, name, property, null); if (value == null) value = ""; results.append(ResponseUtils.filter(value.toString())); } Since value.toString() is used then the default pattern is picked up. Also setting org.apache.struts.taglib.bean.format.sql.date=yyyy/MM/dd in the application resource properties changes the default format of the java.sql.date for bean:write tag. However it does not effect html:text tag. 3. Similar problem happens with date validation by the struts Date validator: <field property="dateOfBirth" depends="required, date"> <var> <var-name>datePatternStrict</var-name> <var-value>yyyy/MM/dd</var-value> </var> <arg0 key="prompt.dob"/> </field> The javascript validation works fine but action form validation does not. The reason is in the method FieldChecks.validateDate(...) that converts form's bean field to string w/out specifying the requested pattern: value = ValidatorUtil.getValueAsString(bean, field.getProperty()); As the result, the default locale date pattern will be used. And then, the method tries to validate that string value against the datePatternStrict specified. The conversion fails unless the default date format matches datePatternStrict (which in most cases it would not otherwise why to specify datePatternStrict at all ?). Dummy custom date validator that does nothing is a work around. --- It seems to me that support for the Date field in ActionForm is very inconsistent and String type is probably easier to use instead( with conversion from/to Date done in the Form/Action manually). A bit more details available at the link provided. Thanks Pavel --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]