I have an input place that should get a number. I want it to be displayed as empty. However when I run my program, I get 0 or 0.00 as default. How can I make it empty?
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- h:selectOneMenu in p:dataTable doesn't submit
- How do I merge consecutive numbers in a sorted lis
- PrimeFaces block UI does not work when the compone
- Jasper: error opening input stream from url
相关文章
- 放在input的text下文本一直出现一个/(即使还没输入任何值)是什么情况
- Show a different value from an input that what wil
- Is there a way to hide the new HTML5 spinbox contr
- Need help generating discrete random numbers from
- Programmatically interrupting raw_input
- Bootstrap input field inside tooltip popover remov
- ValueError: too many values to unpack (expected 2)
- How to allow numbers only using f:validateRegex
You can use inputNumber in primefaces-extension instead of inputText. Like this
In your XHTML code, assume you have your input field as :
In your Managed Bean Action Class, map this field as :
By doing in this way, you won't get 0 or 0.00 as default value in your input fields.
I don't disagree with previous answers given, but I think you might be looking for
and inside the controller
JSF 2.0+
This will happen if you bound the value to a primitive instead of its wrapper representation. The primitive
int
always defaults to0
and the primitivedouble
always defaults to0.0
. You want to useInteger
orDouble
(orBigDecimal
) instead.E.g.:
Then there are two more things to take into account when processing the form submit. First, you need to instruct JSF to interpret empty string submitted values as
null
, otherwise EL will still coerce the empty string to0
or0.0
. This can be done via the following context parameter inweb.xml
:Second, if you're using Tomcat/JBoss or any server which uses Apache EL parser under the covers, then you need to instruct it to not coerce
null
to0
or0.0
in case ofNumber
types by the following VM argument (it's unintuitively dealing withNumber
types as if they are primitives):See also: