Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
789 views
in Technique[技术] by (71.8m points)

jsf - javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL does not work anymore since Java EE 7 / EL 3.0

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...