date field pattern in struts form

P

Pavel

Greetings to all -

I'm struggling with struts processing java.sql.Date field in the
ActionForm correctly. It's related to the date format pattern. I've
set my date pattern in the SqlDateLocaleConverter like this:
static {
SqlDateLocaleConverter dateConverter = new
SqlDateLocaleConverter(Locale.getDefault(), DEFAULT_DATE_PATTERN);
dateConverter.setLenient(false);
ConvertUtils.register(dateConverter, java.sql.Date.class);
}
}
where DEFAULT_DATE_PATTERN="yyyy/MM/dd"

That took care of the date conversion in the struts Action (String
->Date). But if there is a default date value then it's displayed in
the JSP using yyyy-MM-dd format. The same happens if struts action
returns errors to be fixed. The re-displayed date value is converted
from Date to yyyy-MM-dd. 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.

There is a property 'format' in bean:write tag. If I specify
<bean:write name="patientReferralForm" property="dateOfBirth"
format="yyyy/MM/dd"/>
then it outputs exactly what I've asked. Unfortunately, html:text tag
does not support 'format' attribute.

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.

Is there any way to tell struts to use different date pattern for the
text field? Of course, I could use bean:write and add html by myself
instead of html:text but that kind of defeats the purpose of having
html tags.

Any suggestions are greatly appreciated.
Thanks
Pavel

P.S. I'me using struts 1.1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top