2016-09-01 46 views
1

我想更改vaadin的日期字段上的自定义验证消息。在Vaadin DateField中设置自定义验证消息

我的示例图片浏览附...​​

在这里,我想从 “Date format not recognized” 更改为 “Please Enter dd/MM/yyyy date format

+0

你可以发布你的代码吗? – pkkoniec

+0

你尝试使用可用的方法:medateField.setParseErrorMessage(“parseError”); dateField.setConversionError( “conversionError”); 如果这不起作用尝试使用标签并添加blurlistener与验证 – pkkoniec

回答

0

你可以看一下这个链接 https://vaadin.com/docs/-/part/framework/components/components-datefield.html

自定义错误消息

除了定制解析,覆盖处理程序我对于不可分析的输入来说,对于错误消息的国际化和其他自定义非常有用。您还可以使用它的另一种方式报告了错误,如下面的例子来完成:

// Create a date field with a custom error message for invalid format 
PopupDateField date = new PopupDateField("My Date") { 
    @Override 
    protected Date handleUnparsableDateString(String dateString) 
    throws Property.ConversionException { 
     // Have a notification for the error 
     Notification.show(
       "Your date needs two slashes", 
       Notification.TYPE_WARNING_MESSAGE); 

     // A failure must always also throw an exception 
     throw new Property.ConversionException("Bad date"); 
    } 
}; 

如果输入的是无效的,你应该总是抛出异常;返回空值会使输入字段为空,这可能是不希望的。

+0

谢谢你的答案。它显示通知,但我想在网格可编辑内部显示消息 – PONRAJ