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?
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.
This will render 12/03/2018