Liferay date-input displays wrong date

断了今生、忘了曾经 提交于 2019-12-10 11:41:24

问题


I'm using Liferay 7.1 I have the following liferau-ui:input-date object and I want to pre-select a date:

<%
    final LocalDate today = LocalDate.now(ZoneId.systemDefault());
%>

<liferay-ui:input-date
    dayValue="<%= today.getDayOfMonth()%>"
    monthValue="<%=today.getMonth().getValue()%>"
    yearValue="<%= today.getYear()%>"
</liferay-ui:input-date>

When I output today's values directly on the JSP I get the correct date for today: 3 12 2018.

When the element is rendered, it has selected the wrong date: 01/03/2019. There is nothing further documented in the taglibdocs that I think could help.

How can I fix this?


回答1:


The problem is the month value. In Java it's 1-12 with liferay datepicker it's 0-11. In order to display the correct month i subtracted 1 from month value. It's not an elegant solution but i couldn't find any better way.

<liferay-ui:input-date
    dayValue="<%= today.getDayOfMonth()%>"
    monthValue="<%=today.getMonth().getValue() - 1 %>"
    yearValue="<%= today.getYear()%>"
</liferay-ui:input-date>

This will render 12/03/2018



来源:https://stackoverflow.com/questions/53596538/liferay-date-input-displays-wrong-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!