我使用 vaadin 6.6 和 joda DateTime 1.6.2 我使用 How to use DateField with Joda DateTime property? 中描述的解决方案
值设置/获取正确,但不幸的是我得到转换异常:
BeanValidationValidator 中抛出异常:
方法是 JodaDateTime,值是 java.util.Date JodaTime 不能从 Date 分配 JodaTime 没有 String 构造函数
private Object convertValue(Object value) throws Property.ConversionException { // Try to assign the compatible value directly if (value == null || method.getType().isAssignableFrom(value.getClass())) { return value; } else { try { // Gets the string constructor final Constructor constr = method.getType().getConstructor( new Class[] { String.class }); return constr.newInstance(new Object[] { value.toString() }); } catch (final java.lang.Exception e) { throw new Property.ConversionException(e); } } }
你有什么想法吗???
最佳答案
我自己还没有尝试过,但是从我在 BeanValidationValidator 中看到的情况来看,您也需要扩展它并添加 JodaTime 和 java.util.Date 之间的隐式转换。
至少 BeanValidationValidator.validate(Object) 方法需要处理这个转换。
关于datetime - Vaadin 和 Joda 日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6136196/