- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚迁移到 Tomcat 8。我曾经使用系统属性 org.apache.el.parser.COERCE_TO_ZERO=false
因此空字符串、数字、 bool 值等被视为 空
。
在 Tomcat 8、EL 3.0 中,它应该是默认值,但实际上它在 JSF 端将 null
字符串转换为空字符串 ""
。
它应该是 bug它应该被纠正,但我无法让它在 TomEE 快照(Tomcat 8.0.27.0,MyFaces 2.2.8)中工作。
最佳答案
这是 EL 3.0 规范中的一个错误。自 EL 3.0 以来,由于过度热心修复 JSP spec issue 184 , null
在调用模型值 setter 之前将被强制返回空字符串。基本上,javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
不再有任何影响。另请参阅JSF issue 3071和 EL spec issue 18 .
基本上,要解决这个问题,您需要提供一个自定义 EL 解析器,或者将 EL 实现(或者只是整个服务器,因为它是实际提供开箱即用的 EL 的服务器)替换/升级到具有错误修复的版本。 Tomcat issue 57309您链接的内容与这个特定的 EL 3.0 不必要的从 null 到空字符串的强制转换问题无关,它仅与 Tomcat 对自定义 EL 解析器的无知有关。
您可以通过两种方式解决此问题:
提供如下所示的自定义 EL 解析器。确保您使用 Tomcat 8.0.16 或更高版本,如您发现的 Tomcat 问题报告中所指定。
public class EmptyToNullStringELResolver extends ELResolver {
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return String.class;
}
@Override
public Object convertToType(ELContext context, Object value, Class<?> targetType) {
if (value == null && targetType == String.class) {
context.setPropertyResolved(true);
}
return value;
}
@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) {
// NOOP.
}
}
为了让它运行,请在faces-config.xml
中进行如下注册:
<application>
<el-resolver>com.example.EmptyToNullStringELResolver</el-resolver>
</application>
<小时/>或者,切换到 Oracle EL。他们已经将其修复在 version 3.0.1 b05该版本自 2014 年 7 月 7 日起可用(只需选择 newest,即今天起的 3.0.1-b10)。
只需将 javax.el.jar
文件放入 /WEB-INF/lib
中,并将以下上下文参数添加到 web.xml
中为了指示 MyFaces 使用 Oracle EL 实现:
<context-param>
<param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
如果您使用 Mojarra,请使用参数名称 com.sun.faces.expressionFactory
。
由于我自己也一时感到困惑,我在博客上澄清了这一点:The empty String madness .
###另请参阅:
关于jsf - Tomcat 8(和 9)强制行为,空字符串被错误地设置为空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33334192/
我正在尝试用 Java 构建一个字符串,该字符串的长度最多为 3,最少为 1。 我正在根据整数数组的内容构建字符串,如果数组的内容为 -1,我想在字符串中输出一个空字符。否则字符串将包含整数的字符版本
我有一个类,其中有一个方法可以在字符串中包含 NUL 字符的情况下终止程序。具体表达是这样的: stringVar.indexOf('\u0000') < 0 这个字符串是通过 Scanner 从用户
我有一个 wchar_t 数组。我需要在数组中的特定位置添加一个 unicode 空字符。 wchar_t var1[100]; var1[79] = '\u0000'; 我尝试了上面的方法,但出现以
好吧,这听起来可能是重复的,但我已经尝试了所有可能性,例如 str.strip()、str.rstrip()、str.splitline (),还 if-else 检查像: if str is not
System.out.println("-----------------------------------------------------------"); System.out.pr
我有一个奇怪的问题。我从公司内部的许多不同应用程序接收数据,并将这些数据显示在网站上。根据发送数据的系统,数据本身可能在字符串中包含一些奇怪的字符。我的问题是我有一个用户可以搜索以允许其中包含此数据的
我遇到了 aSSL ,这似乎有几年历史了,想知道是否有人有其他“安全”AJAX 连接代码示例?显然,这不如使用 SSL 证书安全,但使用 null character SSL在那里进行攻击(最近针对
我有一个类似于以下内容的 pyspark 数据框: df = sql_context.createDataFrame([ Row(a=3, b=[4,5,6],c=[10,11,12], d='b
我有以下要执行的查询: MyModel.objects.annotate(current_name=Coalesce('nickname', 'name')).order_by('current_na
每当 rails 变量等于 nil(或者实际上每当我使用 rails 代码(参见第 3 个代码示例))时,我的 html 中就会得到一串空字符。 new.html.haml %h1.editable.
我是一名优秀的程序员,十分优秀!