This is a bug in the specification of EL 3.0. Starting with EL 3.0, as a result of over-fixing the JSP 184 specification problem , null will force a return to an empty string before invoking the model's value installer. Essentially, javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL no longer affected. See Also JSF Release 3071 and EL Specification Release 18 .
In fact, to solve this problem you need to either provide your own EL resolver, or replace / update the EL implementation (or just the whole server, since it actually provides EL out of the box) to the bug fix version. The problem of Tomcat 57309 that you linked is not related to this specific EL 3.0 issue of unnecessary casting from empty to empty string, it is only related to Tomcat's ignorance about the EL user recognizer.
You can solve this problem in two ways:
Provide your own EL recognizer as shown below. Make sure you are using Tomcat 8.0.16 or later as indicated in the Tomcat problem report you found.
public class EmptyToNullStringELResolver extends ELResolver { @Override public Class<?> getCommonPropertyType(ELContext context, Object base) { return String.class; } @Override public Object convertToType(ELContext context, Object value, Class<?> targetType) { if (value == null && targetType == String.class) { context.setPropertyResolved(true); } return value; } @Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { return null; } @Override public Class<?> getType(ELContext context, Object base, Object property) { return null; } @Override public Object getValue(ELContext context, Object base, Object property) { return null; } @Override public boolean isReadOnly(ELContext context, Object base, Object property) { return true; } @Override public void setValue(ELContext context, Object base, Object property, Object value) {
To run it, register as faces-config.xml below in faces-config.xml :
<application> <el-resolver>com.example.EmptyToNullStringELResolver</el-resolver> </application>
Or switch to Oracle EL. They have already fixed this in version 3.0.1 b05, which has been available since July 7, 2014 (just select the latest version 3.0.1-b10 to date).
Just javax.el.jar file in /WEB-INF/lib and add the context parameter below to web.xml to tell MyFaces to use the Oracle EL implementation:
<context-param> <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name> <param-value>com.sun.el.ExpressionFactoryImpl</param-value> </context-param>
If you are using Mojarra, use the parameter name com.sun.faces.expressionFactory .
When I, too, got confused for a moment, I wrote on my blog so that everything was in order: the empty frenzy of String .
See also:
source share