简体   繁体   中英

Add DateField in editable grid on vaadin framework

I`m new to Vaadin. In my project I have a grid that was set editable, when I double click on grid, editing is enabled.

In my grid when editing was enabled, in the grid the datefield set as an editable field.

I was using grid.setEditedField(editableField) but it was throwing an error.

gridAssetDetail.getColumn("assignDate").setEditorField(getDateField());
private Field<?> getDateField() { 
  DateField editDate = new DateField();
  editDate.setDateFormat("dd/MM/yyyy");
  return editDate;
}

That way, the String format does not change to datefield.

Error:

Caused by: com.vaadin.data.util.converter.Converter$ConversionException: 
Could not convert '07/04/1914' to java.util.Date 

It seems that your error is due to the conversion from String to Date .

For converting a String to a Date you have to use a DateFormat

String string = "07/04/1914";
DateFormat format = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH);
Date date = format.parse(string);
System.out.println(date);

Or in short:

Date date = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse("07/04/1914");

Source: Java string to date conversion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM