how to assign null to date or integer fields in java

UI Components for JSF
Post Reply
Posts: 3
Joined: 18 Feb 2019, 23:08

06 Mar 2019, 23:38

hi everybody. I am running a project where i use several inputText fields. one calendar object and other integer object.

The problem is when I want to assign null value to these fields there is an error

This would be the code

<!-- This is an input date------------------------------------------------------------
<p:outputLabel for="txtcusuffp3" value="Factura">
<p:calendar id="txtcusuffp3" title="Due date" value="#{ctrl_grupo.dto_custab.duedate}" showOn="button" pattern="dd/MM/yyyy" mask="true" required="false"/>

<p:outputLabel for="txtlongitudp3" value="Salary"></p:outputLabel>
<p:inputText id="txtlongitudp3" title="Ingrese la longitud" value="#{ctrl_grupo.dto_custab.salary}" required="false"></p:inputText>

The problem is when I call a method where I need to assign null to both fields. There is an error , . Automatically the system assigns 0 (zero) to the integer fields but null is not equal to zero and i need a null value in both fields

public void clean_variables() {

duedate.setDate(00 /0 0 /0000); //invalid
salary = null; //invalid
period = 0; //valid
bank = 0; //valid

Date today = Calendar.getInstance().getTime(); //valid



Expert Member
Posts: 9606
Joined: 17 Jun 2010, 13:34
Location: Netherlands

08 Mar 2019, 11:44

Please use stackoverflow for this. Totally not PrimeFaces related

Posts: 7
Joined: 07 Mar 2019, 15:20

08 Mar 2019, 18:19

The JSF EL specification decrees that null is to be converted to 0 prior to assigning a property of numeric type.

You can fix the problem by setting the JVM Parameter of your webserver:
export JAVA_OPTS=-Dorg.apache.el.parser.COERCE_TO_ZERO=false
Before starting the webserver.

You can also set the system properties programmatically using System#setProperty().
System.setProperty("org.apache.el.parser.COERCE_TO_ZERO", "false");

Posts: 1
Joined: 05 Feb 2019, 10:34

18 Mar 2019, 11:01

Any wrapper class with value null will throw java.lang.NullPointerException when Java unbox them into primitive values. ... but when you run above code snippet you will see Exception in thread "main" java.lang.NullPointerException in your console. This happens a lot while working with Mobdro HashMap and Integer key values.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider], HessiJames and 39 guests