DatePicker: crashes with NPE when converting from p:calendar
See original GitHub issueDescribe the defect When migrating from PF8.0 to PF10.0.4 changing p:calendar to p:datePicker causes Null Pointer Exceptions if the referenced object is null. (which is not terribly surprising, but this code works on p:calendar, and I cannot see an easy way around this.)
Environment:
- PF Version: 10.0.4
- JSF + version: JSF 2.3, WildFly 24.0.0_Final
- Affected browsers: ALL
To Reproduce Steps to reproduce the behavior:
- Create a Controller with an object (such as a User object that is NULL initially, as would be the case when editing a user from a table at the point at which the table is rendered, the user object will be null as no user is selected)
- Create a form with the user details, such as userId, email address, date of birth in a dialog that will be opened on selecting the user
- Change p:calendar to p:datePicker
- NPE
Expected behavior No NPE
Example XHTML
<h:form id="frmTest">
<p:calendar id="dateOfBirth" value="#{userController.selectedUser.dateOfBirth}"/>
</h:form>
vs
<h:form id="frmTest">
<p:datePicker id="dateOfBirth" value="#{userController.selectedUser.dateOfBirth}"/>
</h:form>
Example Bean
@Named
@ViewScoped
public class UserController implements Serializable {
private Users selectedUser;
//at this point selectedUser is null (as would be the case with a table where nothing is selected)
public Users getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(Users selectedUser) {
this.selectedUser = selectedUser;
}
}
The above code works PERFECTLY with p:calendar, but p:datePicker crashes:
SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-65) Error Rendering View[/secured/otherusers.xhtml]: javax.el.PropertyNotFoundException: /secured/edituserdialog.xhtml @82,86 value=“#{userController.selectedUser.dateOfBirth}”: Target Unreachable, ‘null’ returned null at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:64) at deployment.ProjectName-1…0.war//org.primefaces.component.api.UICalendar.getTypeFromValueByValueExpression(UICalendar.java:356) at deployment.ProjectName-1.0.war//org.primefaces.component.datepicker.DatePickerRenderer.encodeEnd(DatePickerRenderer.java:59) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:595) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1654) at javax.faces.api@3.0.0.SP04//javax.faces.render.Renderer.encodeChildren(Renderer.java:152) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:566) at deployment.ProjectName-1.0.war//org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:72) at deployment.ProjectName-1.0.war//org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:59) at deployment.ProjectName-1.0.war//org.primefaces.component.dialog.DialogRenderer.encodeContent(DialogRenderer.java:195) at deployment.ProjectName-1.0.war//org.primefaces.component.dialog.DialogRenderer.encodeMarkup(DialogRenderer.java:118) at deployment.ProjectName-1.0.war//org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.java:47) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:595) at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:286) at com.sun.jsf-impl@2.3.14.SP04//com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:90) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:566) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1647) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650) at javax.faces.api@3.0.0.SP04//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (8 by maintainers)

Top Related StackOverflow Question
I actually think it should not have worked in Calendar and the above error is correct?
Tested locally now I am letting the whole Integration Test suite run.