Apache el 实现执行空字符串(或 0 int 值)。您可以在 org.apache.el.parser.AstValue 类中找到它:
public void setValue(EvaluationContext ctx, Object value)
throws ELException {
Target t = getTarget(ctx);
ctx.setPropertyResolved(false);
ELResolver resolver = ctx.getELResolver();
// coerce to the expected type
Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
if (COERCE_TO_ZERO == true
|| !isAssignable(value, targetClass)) {
resolver.setValue(ctx, t.base, t.property,
ELSupport.coerceToType(value, targetClass));
} else {
resolver.setValue(ctx, t.base, t.property, value);
}
if (!ctx.isPropertyResolved()) {
throw new PropertyNotFoundException(MessageFactory.get(
"error.resolver.unhandled", t.base, t.property));
}
}
您可以将 COERCE_TO_ZERO 设置为 false (-Dorg.apache.el.parser.COERCE_TO_ZERO=false)。
或者使用其他 el impl:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
并设置上下文参数:
servletContext.setInitParameter("com.sun.faces.expressionFactory", "com.sun.el.ExpressionFactoryImpl");
那是 el-api 方面。
另一边是JSF。您必须为 JSF 设置此上下文参数:
servletContext.setInitParameter("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL", "true");
对不起我的英语不好!