[英]JSF 2 - hiding default values on <? extends Number>
is there a way to hide the default values of my number properties? 有没有办法隐藏我的数字属性的默认值? I've got a
int
field and on my view the <h:inputText />
field shows a 0. In addition to this, if I leave this input empty I get a NullPointerException
on this. 我有一个
int
字段,在我看来, <h:inputText />
字段显示为0.除此之外,如果我将此输入留空,我会得到一个NullPointerException
。
Can I hide the default value and treat empty inputs as default value? 我可以隐藏默认值并将空输入视为默认值吗?
I'm using mojarra 2.1.2
on Tomcat 7
我在
Tomcat 7
上使用mojarra 2.1.2
The primitive int
always defaults to 0
. 原始
int
始终默认为0
。 You want to use Integer
instead. 您想要使用
Integer
。 Eg: 例如:
public class Entity {
private Integer value;
// ...
}
As to keeping it null
while submitting empty data, add the following context param to your web.xml
: 至于在提交空数据时保持
null
,请将以下上下文参数添加到web.xml
:
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
In addition, if you're using Tomcat or a clone which utilizes Apache EL parser, add the following server startup VM argument as well to prevent it from treating Number
values like primitives: 此外,如果您正在使用Tomcat或使用Apache EL解析器的克隆,请添加以下服务器启动VM参数,以防止它将
Number
值视为基元:
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
In Eclipse, you could set it in server configuration (doubleclick the server entry in Servers view) in the Arguments tab of the Open launch configuration dialogue. 在Eclipse中,您可以在Open launch配置对话框的Arguments选项卡中将其设置为服务器配置(在Servers视图中双击服务器条目)。 In production, you could add it to the
JAVA_OPTS
environment variable. 在生产中,您可以将其添加到
JAVA_OPTS
环境变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.