I have a component,where users can choose to set any date at all even null, but when the date is not null, it should render a panel to allow for other options. But, the date is not getting updated and is always null as a result it never renders the panel. Help needed on this. Below is my code:
<p:calendar id="dt"
value="#{user.deadline}"
pattern="MM/dd/yyyy"
showOn="button"
mindate="#{userr.minDate}">
<f:validator validatorId = "dateValidator"/>
<f:attribute name="minDate" value="#{user.minDate}" />
<p:ajax event="dateSelect" listener="#{user.updateDeadlineDate}" update=":userForm:userReminderForm"/>
</p:calendar>
<p:panel id= "myPanel" rendered="#{user.getDeadline != null}">
.. some component that needs user.deadline
</p:panel>
snippet from my bean:
public Date getDeadline() {
return deadline;
}
public void setDeadline(Date deadline) {
this.deadline=deadline;
}
public void updateDeadlineDate(DateSelectEvent event) {
this.setDeadline(event.getDate());
}
First, your update target is probably wrong (nested forms
:userForm:userReminderFormare invalid in HTML/JSF), maybe you wanted to doupdate=":userForm"(since you can’t update the panel directly as siebz0r pointed out):The
getDeadlineis unnecessary, when you reference backing bean properties just use their names likedeadline.Note that you can use the validator of the calendar component, so you can avoid the additional
<f:validator validatorId = "dateValidator"/>tag.Your
<f:attribute name="minDate" value="#{user.minDate}" />tag is probably unnecessary in this case. If you want to set yourdeadlineto the value ofminDate(since they are in the same bean) just do:and remove the
<f:attribute name="minDate" value="#{user.minDate}" />.Finally I would use the
emptykeyword in therenderedattribute instead of!= null:rendered="#{not empty user.deadline}"