![](/img/trans.png)
[英]using javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL causes viewParam to be null
[英]JSF 2.2 interpret empty string submitted values as null not working
我已經從Java EE 6遷移到Java EE 7,現在使用JSF 2.2,上下文參數INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
似乎不起作用。 在JSF 2.1中我將它設置為“true”並且它完美地工作,但現在我總是得到空字符串。
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
誰能說點什么呢?
使用最新的Mojarra-2.2.5以及Wildfly 8 Final的glassfish 4也是如此。 。 。 我已經看到了關於此的多個錯誤報告,Manfried Riem說“已經確定這是一個EL問題並且已經修復了EL實現以修復此問題”,但不確定這是否意味着更新Mojarra修復它,因為它不在glassfish中我也更新了el,但也沒有用。
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>
並設置context-param:
servletContext.setInitParameter("com.sun.faces.expressionFactory", "com.sun.el.ExpressionFactoryImpl");
那是el-api方面。
另一方面是JSF。 你必須為JSF設置這個context-param:
servletContext.setInitParameter("javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL", "true");
對不起我的英語不好!
在類似的情況下,應用程序服務器有一個JVM屬性幫助了我。 請參閱Mojarra JSF 2.1中的錯誤INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL的解決方法
我已經嘗試過下面的工作了。 我們需要在web.xml中添加此條目
<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>true</param-value>
</context-param>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.