0

I have a JSF 2.0 application on Weblogic 12c. I have a variable of Integer type in an Entity accepting input type="text" on the JSF side.

The issue is, on save, the Integer variable is getting set to 0 if the user does not enter any value in the field. I need it to be null. I searched for previous questions but only found answers for Tomcat which didnt work for me. How do I fix this?

private Integer code;

public Integer getCode() {
    return this.code;
}

public void setCode(Integer code ) {
    this.code = code ;
}
Snehal
  • 1

1 Answers1

0

This might not answer why it is happening, but to 'fix' the issue you might try something similar to this:

public void setCode(Integer code ) {
    if (code == null || code.intValue() == 0) {
        this.code = null;
    }
    this.code = code;
}

This would only 'work' as a fix if you know your code value should never actually be 0.

George Andrews
  • 279
  • 3
  • 9