Vaadin Grid如果日期是12月31日,则显示错误的年份
我创建了一个vaadin网格,并将setItems方法与返回分页流的自定义JPA存储库结合使用。当网格必须显示特定日期(2019-12-31)的日期时,就会出现问题,它将自动显示“ 31.12.2020”,看起来日期以某种方式跳到了明年。
这里的网格
private Grid<Budget> createGrid() {
Grid<Budget> grid = new Grid<>(Budget.class, false);
grid.setPageSize(100);
grid.setSortableColumns();
grid.addColumn(new LocalDateRenderer<>(Budget::getValidfrom, "dd.MM.YYYY")).setHeader("Gültig von");
grid.addColumn(new LocalDateRenderer<>(Budget::getValidto, "dd.MM.YYYY")).setHeader("Gültig bis");
for (Grid.Column<Budget> c : grid.getColumns()) {
c.setAutoWidth(true).setFlexGrow(2);
}
return grid;
}
在这里如何填充数据库中的网格
grid.setItems(query -> service.getLimitData(filter, query.getPage(), query.getPageSize()).stream());
I've created a vaadin grid and used the setItems method in combination with a custom jpa repository that returns a paged stream. The problem appears when the grid has to show a date with a specific date (2019-12-31), it will automatically show "31.12.2020", looks like the date is somehow jumping to the next year.
here the grid
private Grid<Budget> createGrid() {
Grid<Budget> grid = new Grid<>(Budget.class, false);
grid.setPageSize(100);
grid.setSortableColumns();
grid.addColumn(new LocalDateRenderer<>(Budget::getValidfrom, "dd.MM.YYYY")).setHeader("Gültig von");
grid.addColumn(new LocalDateRenderer<>(Budget::getValidto, "dd.MM.YYYY")).setHeader("Gültig bis");
for (Grid.Column<Budget> c : grid.getColumns()) {
c.setAutoWidth(true).setFlexGrow(2);
}
return grid;
}
here how I fill the grid
grid.setItems(query -> service.getLimitData(filter, query.getPage(), query.getPageSize()).stream());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tl; dr
更改
yyyy
touuuu
纠正您的格式模式。您的问题与 vaadin 无关。日期格式是标准Java。
基于周的年度与日历年
您的格式代码不正确。
大写
yyyy
是指基于一周的年度,而不是日历年。该代码使用 iso 8601几周的定义 neeks and Base Base and Base Base year 星期一,运行整整7天,第一周包含日历年的第一个星期四。这意味着基于本周的第一周和最后几周可能有几天/下一个日历年的几天。因此,您遇到的意外一年是一个功能,而不是错误。
tl;dr
Change
YYYY
touuuu
to correct your formatting pattern.Your issue has nothing to do with Vaadin specifically. Date formatting is standard Java.
Week-based year versus calendar year
Your formatting code is incorrect.
Uppercase
YYYY
means a week-based year, not a calendar year. That code uses the ISO 8601 definition of weeks and week-based year: Week starts on Monday, runs a full 7 days, and first week contains the first Thursday of the calendar year. That means the first and last weeks of the week-based year may have a few days from the previous/next calendar year.So the unexpected year you encountered is a feature, not a bug.
???? For calendar-year, use lowercase
yyyy
oruuuu
.These formatting pattern codes are documented on the Javadoc for the
DateTimeFormatter
class.