Add something like the following (tweak the date formats) to your
AppModule.java:
public static void contributeTranslatorDefaultSource(
MappedConfiguration<Class<?>, Translator<?>> configuration)
{
configuration.add(Date.class, new Translator<Date>()
{
/**
* Parses blank values to null, otherwise parses the client value
to a date
*
* @throws ValidationException if the clientValue can not be parsed
*/
public Date parseClient(String clientValue, Messages messages)
throws ValidationException
{
if (InternalUtils.isBlank(clientValue))
return null;
try
{
String input = clientValue.trim();
return DateUtils.parseDate(input, new String[]{"yyyy/MM/dd",
"yyyy.MM.dd",
"yyyy-MM-dd"});
}
catch (ParseException e)
{
throw new
ValidationException(messages.format("date-format-exception",
clientValue));
}
}
/**
* Converts null to an empty string, non-null to a string
representation.
*/
public String toClient(Date value)
{
return value == null ? "" : value.toString();
}
});
}
Cheers,
Nick.
Joshua Jackson wrote:
Dear all,
Currently I have a field with java.util.Date type in my page, but it
seems that the java.util.Date type is not yet supported in Tapestry5.
This is the exception that I get:
org.apache.tapestry.ioc.internal.util.TapestryException
No adapter from type java.util.Date to type
org.apache.tapestry.Translator is available (registered types are
java.lang.Double, java.lang.Integer, java.lang.Long,
java.lang.String).
What is the workaround if I wanted to have java.util.Date field? While
waiting for these feature to be added on the next release.
Thanks in advance
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]