• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsf inputtext with empty value for integer type managed bean variable.

 
Siew Ling
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I know is it able to set the input text to empty when my managed bean for the variable is in integer type?

I have a managed bean as the following:


My inputtext in the jsf page as the following:



And when i run my page, the text box shows 0.
I would like it to just show empty.





 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to make your bound variable Integer with initial value as null !
 
Siew Ling
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
But how can I make the initial value as null?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF will not permit the entry of invalid data. That's one of its core concepts. And there is no number that corresponds to "".

If you use the Integer data type instead of "int", then setting it to null might work, but I won't guarantee it. I don't know what the spec says is supposed to happen and I'm too lazy to RTFM.

The only way I can guarantee that an empty value will be accepted is if you define the property as a String. However you would then need a validator to prevent non-numeric data from being set in the backing bean.
 
Siew Ling
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much, I have change the type to Integer and it works as what I want
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic