JSF EJB3到Spring 3,BigInteger总是0而不是null

djn*_*ose 3 java jsf spring tomcat el

我对我的webapplication的奇怪行为感到疯狂.我不得不将它从EJB3更改为Spring,现在我面临一个(至少对我而言)奇怪的错误.我有一些正常的JSF页面(Primefaces 3.4)并创建了一些Filter.这一切都很好,但我的所有过滤BigInteger值现在总是0代替null.结果是,我的db-query现在总是添加0 - values到我的查询..这不是我想要的.每个建议都将非常感激.我已经添加了

   <context-param>
      <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
      <param-value>true</param-value>
  </context-param>
Run Code Online (Sandbox Code Playgroud)

到我的WEB.xml,但这并没有改变任何东西......

编辑: 因此,解决方案是将EL从Tomcat 7.0更改为"标准"EL.这有点奇怪.我的web.xml现在看起来像这样:

  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
  </context-param>
Run Code Online (Sandbox Code Playgroud)

我的pom看起来像那样:

 <dependency>
     <groupId>javax.el</groupId>
     <artifactId>el-api</artifactId>
     <version>2.2</version>
  </dependency>
  <dependency>
     <groupId>org.glassfish.web</groupId>
     <artifactId>el-impl</artifactId>
     <version>2.2</version>
  </dependency>
Run Code Online (Sandbox Code Playgroud)

哇...现在它起作用..仍然困惑......

Bal*_*usC 5

此行为特定于Tomcat 6.0.16及更高版本.这是严格按照EL规范其说,这个数字类型应该被强制为零,并给予该优先应强制转换为对象类型null.换言之,不仅是数量的原语,如int,long等,被强制为零,而且其包装类型表示,如Integer,Long,BigInteger,BigDecimal,等被强制零代替null.

您需要添加以下VM参数以禁用此不直观的行为:

-Dorg.apache.el.parser.COERCE_TO_ZERO=false
Run Code Online (Sandbox Code Playgroud)

您当然也可以像Glassfish EL实现一样替换Tomcat EL实现(请注意,它不是您所暗示的"标准EL",它只是"参考实现").

请注意,这一切都与Spring或EJB无关,它只是巧合或不正确的观察.

也可以看看: