JSF – integer gets the default value 0, which needs to be null in Java
See English answer > H: inputtext which is bound to integer property is submitting value 0 instead of null1
All I need is to insert "null" into the Oracle database without passing it from the inputtext field of the UI
PaymantSpecFormPage. xhtml
<h:inputText id="startWeek" value="#{flowScope.paymentSpecVO.paymStartWk}" styleClass="inputTypeForm" maxlength="4"/>
PaymentSpecVO. java
public class PaymentSpecVO extends BaseVO<PaymentSpec> { private Integer paymStartWk; public Integer getPaymStartWk() { return paymStartWk; } public void setPaymStartWk(Integer paymStartWk) { this.paymStartWk = paymStartWk; } }
In my DB table
COLUMN_NAME DATA_TYPE NULLABLE DEFAULT_VALUE ------------ --------- -------- ------------- PAYM_START_WK NUMBER(4,0) Yes null
When I enter anything in inputtext, instead of null, 0 is entered into the table, which has different meanings in my business logic. Please help me make necessary code changes
Solution
This problem is recognizable because Tomcat's El parser does not consider that you use integer instead of int. you need to add the following VM parameters to Tomcat startup options:
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
You can also see:
> h:inputText which is bound to Integer property is submitting value 0 instead of null > Work around for faulty INTERPRET_ EMPTY_ STRING_ SUBMITTED_ VALUES_ AS_ NULL in Mojarra JSF 2.1
This problem can be recognized by JDBC, using resultset #getint() instead of resultset #getobject() However, this is basically a different problem from the first one You didn't tell me anything about your database access layer settings, so it's hard to point out a specific solution