struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dimitar Vlasev" <>
Subject Re: Dojo datetimepicker problem
Date Wed, 03 Dec 2008 10:57:03 GMT
Few findings:
at section "Built in Type Conversion Support" documentation says:

XWork will automatically handle the most common type conversion for
you. This includes support for converting to and from Strings for each
of the following:
 -> dates - uses the SHORT format for the Locale associated with the
current request

But I haven't tried yet to utilize this feature.

This is what worked for me:

What I've done was to create custom type conversion class
public class ShortDateConverter extends StrutsTypeConverter {
	public final static String pattern = "dd.MM.yyyy";
	private final static SimpleDateFormat format = new SimpleDateFormat(pattern);

	public Object convertFromString(Map context, String[] values, Class toClass) {
		Date result = null;

		if (values != null && values.length > 0) {	
			try {
				result = format.parse(values[0]);
			} catch (ParseException e) {
				throw new TypeConversionException("Error converting date from '" +
values[0] + "', pattern: '" + pattern + "'");
		return result;

	public String convertToString(Map context, Object o) {
		return null;


and applied it to the setter method within my action class:
(it worked well both using annotation and
<action_class_name> file)
	@TypeConversion (type=ConversionType.CLASS,
	public void setADate(Date date) {

Though it would be even elegant enough solution if I was able to refer
to the static pattern String in the .jsp like that
<s:datetimepicker displayFormat="<%=ShortDateConverter.pattern%>"/>
But I got exception:
According to TLD or attribute directive in tag file, attribute
displayFormat does not accept any expressions

I hope these findings will help someone else.

Dimitar Vlasev

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message