2016-08-02 89 views
0

我的问题是如果我在我的Web应用程序的UI中使用vaadin框架(如下面的代码)放置日期字段,那么如何为其设置默认日期值?我还可以在eclipse编辑器中看到带有date字段的setValue()方法建议,但没有太多关于如何在文档中使用setValue()设置特定日期的信息。Vaadin datefield组件设置默认日期

DateField dueDate = new DateField(); 
dueDate.setDateFormat("dd-MM-yyyy"); 
dueDate.setVisible(true); 
dueDate.setCaption("Due Date"); 
**dueDate.setValue();** 

在此先感谢您的关注。我正在使用vaadin7。

回答

1

这确实是您需要调用的setValue方法。您可以提供java.util.Date对象。第一个代码示例this documentation page显示它。

// Create a DateField with the default style 
DateField date = new DateField(); 

// Set the date and time to present 
date.setValue(new Date()); 

如果你是在Java的8要使用LocalDateLocalDateTime,你需要将其转换为java.util.Date或写为DateField一个Converter(我这样做,前一段时间,见here)。