[英]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不适用于 glassfish 4 和 wildfly 8 Final 上的最新 Mojarra 2.2.5
I have seen multiple bug reports on this, Manfried Riem says ,曼弗里德·里姆( Manfried Riem) 说,我已经看到多个关于此的错误报告,
It was determined this is an EL issue and the EL implementation has been fixed to fix this
已确定这是一个 EL 问题,并且已修复 EL 实现以解决此问题
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.5,在 2.2.5 的发行说明中也有说明,我是不是遗漏了什么?
Fixed with a custom resolver:使用自定义解析器修复:
faces-config.xml:面孔-config.xml:
<application>
<el-resolver>my.package.EmptyNullStringResolver</el-resolver>
</application>
EmptyNullStringResolver.java: 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;
}
}
I have seen multiple bug reports on this, Manfried Riem says ,
曼弗里德·里姆( Manfried Riem) 说,我已经看到多个关于此的错误报告,
It was determined this is an EL issue and the EL implementation has been fixed to fix this
已确定这是一个 EL 问题,并且已修复 EL 实现以解决此问题
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.5,在 2.2.5 的发行说明中也有说明,我是不是遗漏了什么?
The actual fix is in EL, not in JSF.实际的修复是在 EL 中,而不是在 JSF 中。 The Mojarra version mentioned in the issue report was just "concidentally" the latest Mojarra version at that moment.
问题报告中提到的 Mojarra 版本只是“偶然地”当时最新的 Mojarra 版本。 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).基本上,要解决这个问题,您需要升级 EL 实现(或者只是升级整个服务器,因为它是实际提供开箱即用 EL 的服务器)。 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).
对于 Oracle/Sun EL,该修复程序在3.0.1 b05 版本中,该版本自 2014 年 7 月 7 日起可用(只需选择最新版本)。 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:您可以将 JAR 放在
/WEB-INF/lib
并在必要时将以下配置添加到web.xml
,以防您的服务器附带与 Oracle/Sun EL 不同的 EL 实现,这也暴露了相同的错误:
<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 :或者您可以安装替代 EL 实现,例如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
.如果您使用的是 MyFaces 而不是 Mojarra,请使用
org.apache.myfaces.EXPRESSION_FACTORY
<param-name>
。
As to upgrading the server, the EL version with the fix is present in at least GlassFish 4.1 and WildFly 8.2.至于升级服务器,至少在 GlassFish 4.1 和 WildFly 8.2 中存在带有修复的 EL 版本。
The sample codes obj condition checking is wrong.示例代码 obj 条件检查是错误的。 At update model phase, the obj is passed at null.
在更新模型阶段,obj 以空值传递。 After correct to the code below, my custom ELResolver works.
更正下面的代码后,我的自定义 ELResolver 工作。
@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;
}
There's a JVM parameter for the application server that helped me.应用程序服务器有一个 JVM 参数对我有帮助。 See Work around for faulty INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL in Mojarra JSF 2.1
请参阅解决 Mojarra JSF 2.1 中错误的 INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
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.我们在 Tomcat 7.0.xx 或 Tomcat 8.0.30 中测试了所有 Oracle EL 2.2.2、3.0.0、3.0.1-b0X[1-8] 和 Apache Jasper EL 3.0,使用或不使用带有 ELResolver 固定 @faces 的自定义 ELResolver Wrapper -config.xml 级别。
The result is the same.结果是一样的。 String MethodExpression null is interpreted as EMPTY String ""
String MethodExpression null 被解释为 EMPTY String ""
Calling from EL the following methods with t=null;使用 t=null 从 EL 调用以下方法;
Case 1情况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案例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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.