Few findings:
http://struts.apache.org/2.0.14/docs/type-conversion.html
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>-conversion.properties file)
-----------------
        @TypeConversion (type=ConversionType.CLASS,
converter="test.ShortDateConverter")
        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.


Regards,
Dimitar Vlasev

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to