JSF 2 - 隐藏&lt ;?上的默认值extends Number> [英] JSF 2 - hiding default values on <? extends Number>

查看:108
本文介绍了JSF 2 - 隐藏&lt ;?上的默认值extends Number>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法隐藏我的号码属性的默认值?我有一个 int 字段,在我看来,< h:inputText /> 字段显示为0除此之外,如果我将此输入留空,我会得到一个 NullPointerException

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.

我可以隐藏默认值并将空输入视为默认值吗?

Can I hide the default value and treat empty inputs as default value?

我正在使用 mojarra 2.1.2 on Tomcat 7

推荐答案

原语 int 始终默认为 0 。您想要使用 Integer 。例如:

The primitive int always defaults to 0. You want to use Integer instead. E.g.:

public class Entity {

    private Integer value;

    // ...
}

关于保持提交空数据时, null ,将以下上下文参数添加到 web.xml

As to keeping it null while submitting empty data, add the following context param to your web.xml:

<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param>

此外,如果您使用的是Tomcat或使用Apache EL解析器的克隆,请添加以下内容:服务器启动VM参数也是为了防止它处理 Number 这些值,如原语:

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:

-Dorg.apache.el.parser.COERCE_TO_ZERO=false

在Eclipse中,您可以在服务器配置中设置它(双击 Servers 视图)在打开启动配置对话框的参数选项卡中。在生产中,您可以将其添加到 JAVA_OPTS 环境变量中。

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. In production, you could add it to the JAVA_OPTS environment variable.

这篇关于JSF 2 - 隐藏&lt ;?上的默认值extends Number&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆