h:inputText return a empty string instead of NULL

You can configure JSF 2.x to interpret empty submitted values as null by the following context-param in web.xml:
<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param>

Here is a long explanation. Section 11.1.3 of the JSF spec says:

javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL -- If this param is set, and
calling toLowerCase().equals("true") on a String representation of its value returns true, any
implementation of UIInput.validate() must take the following additional action.
If the javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL context parameter value is
true (ignoring case), and UIInput.getSubmittedValue() returns a zero-length String call
UIInput.setSubmittedValue(null) and continue processing using null as the current submitted value.

This is indeed being done. However, when UIInput.updateModel() is called, that triggers the EL Evaluation, which will coerce the value based on its expected type. If it sees that the expected type is a String then it will convert a null to empty string. So eventually, your managed bean will be set with empty string instead of null. That behavior is governed by the EL spec.

你可能感兴趣的:(empty,h:inputText,JSF2.X)