question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DatePicker: crashes with NPE when converting from p:calendar

See original GitHub issue

Describe 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:

  1. 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)
  2. 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
  3. Change p:calendar to p:datePicker
  4. 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:closed
  • Created 2 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, Jul 21, 2021

I actually think it should not have worked in Calendar and the above error is correct?

0reactions
mellowarecommented, Aug 23, 2021

Tested locally now I am letting the whole Integration Test suite run.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[MaterialDatePicker] Switching mode causes crash #1946
Description: Following workflow only crashes on my API 30 emulator: Opened MaterialDatePicker; Switched to Text-Mode; Switched to Calendar-Mode ...
Read more >
DatePicker crashes when select date beyond min or max date ...
DatePicker needs to be inited to be able to set min or max date. I just change dialog.show() before it. :\ Calendar calender...
Read more >
Datepicker Dialog V1.0.0 | Page 2 | B4X Programming Forum
This looks like a nice date picker that looks like the KitKat one but it crashes my app when I tap on the...
Read more >
[Solved]-App Crashes When Switching from Splash Screen to ...
Coding example for the question App Crashes When Switching from Splash Screen to ... OnDateSetListener() { @Override public void onDateSet(DatePicker view, ...
Read more >
changelog-1.5 - Apache
ILinkCallback have onClick method * [WICKET-3736] - npe in StoredResponsesMap * [WICKET-3739] - wicket-datetime datepicker fails to display calendar with js ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found