I have a primefaces p:calendar component, from which I select different dates.
I need to get the selected date value in Java, but none of the approaches I tried seems to work, as I always get a null object from the event. My code currenyly looks like below:
Xhtml:
<p:calendar id="inputField_#{assetDetail.sanitizeId(field.name)}"
value="#{assetDetail.dataFieldValuesMap[field.name]}"
pattern="yyyy-MM-dd" styleClass="datafield-value"
rendered="#{assetDetail.editMode}">
event="dateSelect" listener="#{assetDetail.creationDateChange}"/>
</p:calendar>
Java backend:
public void creationDateChange(SelectEvent<Date> event) {
Date selectedDate = event.getObject();
if (selectedDate != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = sdf.format(selectedDate);
System.out.println(formattedDate);
} else {
System.out.println("Event Object is null.");
}
}
The variable event.getObject() returns null every time, the method is being triggered right though, so I really cannot figure out where the problem is.
Can anyone help?