<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
Does not work with the latest Mojarra 2.2.5 on both glassfish 4 and wildfly 8 Final
I have seen multiple bug reports on this, Manfried Riem says,
It was determined this is an EL issue and the EL implementation has been fixed to fix this
The fix versions says 2.2.5, and it is also stated in the release notes of 2.2.5, am I missing something?
I have seen multiple bug reports on this, Manfried Riem says,
It was determined this is an EL issue and the EL implementation has been fixed to fix this
The fix versions says 2.2.5, and it is also stated in the release notes of 2.2.5, am I missing something?
The actual fix is in EL, not in JSF. The Mojarra version mentioned in the issue report was just "concidentally" the latest Mojarra version at that moment. See also The empty String madness.
Basically, to solve this problem you need to upgrade the EL implementation (or simply the whole server as it's the one actually providing EL out the box). In case of Oracle/Sun EL, the fix is in version 3.0.1 b05 which has been available since 7 July 2014 (just pick the newest one). You can just drop the JAR in /WEB-INF/lib
and if necessary add the below configuration to web.xml
in case your server ships with a different EL implementation than Oracle/Sun EL which also exposes the same bug:
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
Or you can install an alternative EL implementation, such as JUEL:
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>de.odysseus.el.ExpressionFactoryImpl</param-value>
</context-param>
In case you're using MyFaces instead of Mojarra, use <param-name>
of org.apache.myfaces.EXPRESSION_FACTORY
.
As to upgrading the server, the EL version with the fix is present in at least GlassFish 4.1 and WildFly 8.2.
Fixed with a custom resolver:
faces-config.xml:
<application>
<el-resolver>my.package.EmptyNullStringResolver</el-resolver>
</application>
EmptyNullStringResolver.java:
/**
* @author pg
*/
public class EmptyNullStringResolver extends ELResolver {
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return String.class;
}
@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) {
}
@Override
public Object convertToType(ELContext context, Object obj, Class<?> targetType) {
if (String.class.equals(targetType) && obj instanceof String && ((String) obj).trim().isEmpty()) {
context.setPropertyResolved(true);
}
return null;
}
}
The sample codes obj condition checking is wrong. At update model phase, the obj is passed at null. After correct to the code below, my custom ELResolver works.
@Override
public Object convertToType(final ELContext context, final Object obj, final Class<?> targetType) {
if (obj == null && String.class.equals(targetType)) {
context.setPropertyResolved(true);
}
return null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With