9
<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?

2
  • 2
    Just for the records: WildFly 8.1 still has this problem. Jul 22, 2014 at 13:51
  • Wildfly 8.2 seems to be working
    – Fabio B.
    Dec 5, 2014 at 13:14

5 Answers 5

12

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;
    }
}
2
  • Using latest glassfish 4.0.1 still broken
    – rekiem87
    Apr 10, 2014 at 20:34
  • Balus C has a slight variation on the convertToType function (balusc.omnifaces.org/2015/10/the-empty-string-madness.html) public Object convertToType(ELContext context, Object value, Class<?> targetType) { if (value == null && targetType == String.class) { context.setPropertyResolved(true); } return value; }
    – Michael
    Jun 12, 2019 at 9:07
5

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.

5
  • Hi BalusC, this not work for me. I'm using Tomcat 8.0.28 and Maven to download <dependency><groupId>org.glassfish</groupId><artifactId>javax.el</artifactId><version>3.0.1-b05</version><scope>compile</scope></dependency> and still not working. I configure the web.xml like you did but not work. I really be grateful if you can test and help me to solve this problem. Oct 21, 2015 at 4:17
  • @Diego: it has to end up in runtime classpath.
    – BalusC
    Oct 21, 2015 at 7:33
  • I change the scope of dependency to runtime, but still not working. Oct 21, 2015 at 10:52
  • I've found the solution (tested on tomcat 8). The configuration shown is still incomplete. To work properly, without any "workaround", is necessary beyond what has already been shown in response to put on web.xml the context-param: "<context-param><param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_‌​A‌​S_NULL</param-name><param-value>true</param-value></context-param>". Now, works like a charm. Oct 21, 2015 at 14:54
  • @Diego: yes, the point of the answer is to get that context param to work. See also the question.
    – BalusC
    Oct 21, 2015 at 19:02
1

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;
}
0

There's a JVM parameter for the application server that helped me. See Work around for faulty INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL in Mojarra JSF 2.1

0

We tested all Oracle EL 2.2.2, 3.0.0, 3.0.1-b0X[1-8] and with Apache Jasper EL 3.0 in Tomcat 7.0.xx or Tomcat 8.0.30 using or not custom ELResolver Wrapper with ELResolver fixed @ faces-config.xml level.

The result is the same. String MethodExpression null is interpreted as EMPTY String ""

Calling from EL the following methods with t=null;

Case 1

public final void checkObject(Object t) 
...
#{myBean.checkObject(null)} -> Receive null (OK)

Case 2

public final void checkString(String t) 
...
#{myBean.checkString(null)} -> Receive EMPTY String "" (NOT OK)

Case 3

public final void checkDouble(double t) 
...
#{myBean.checkDouble(null)} -> Receive 0.0 (OK)

Case 4

public final void checkBigDecimal(BigDecimal t) 
...
#{myBean.checkBigDecimal(null)} -> Receive null (OK) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.