Hi,
When binding a JSF input text to a String property of a JSF ManagedBean, I
want that an empty value is mapped to null and not "" (empty string).
So, on tomcat7 (7.0.56) with JSF(2.2 RI) I can get this to work nicely by
controlling the coercing behavior with the JVM property
org.apache.el.parser.COERCE_TO_ZERO icw JSF
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL as context
param.
When javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is set to
true, JSF will set the local component value for the input component as null
when the input if left empty.
Next, when the value is actually set by tomcat's EL parser, it will NOT try
to coerce the value when org.apache.el.parser.COERCE_TO_ZERO is set to false
and the value remains null as I want (= OK)
However (as I first posted this on the tomcat dev mailinglist) as of Tomcat8
and EL3 , a null value is coerced to "" (empty String) by the EL parser and
the COERCE_TO_ZERO property has no longer any effect.
This is as the specification now by default converts "" to null in case of a
non-primitive number. But, in case of String, the specs says that a empty
string ("") is not coerced to null and remains empty String.
The relevant parts from the EL 3 spec:
1.23.2 Coerce A to String
If A is null: return ""
1.23.3 Coerce A to Number type N
If A is null and N is not a primitive type, return null.
If A is null or "", return 0.
My questions:
- Wrt EL3, does the JSF param
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL has any use
left?
Since the EL impl converts the null resulting from this property to empty
String according to the spec
- Is there a way that I can change this behavior in any way so that
I can have null instead of empty String for empty text fields with
Tomcat8/JSF2.2 RI?
Thanks,
Koen.