aspose file tools*
The moose likes JSF and the fly likes jsf inputtext with empty value for integer type managed bean variable. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf inputtext with empty value for integer type managed bean variable." Watch "jsf inputtext with empty value for integer type managed bean variable." New topic
Author

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

Siew Ling
Greenhorn

Joined: Jan 08, 2013
Posts: 6
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 Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Try to make your bound variable Integer with initial value as null !


True person is moral, false is right!
Siew Ling
Greenhorn

Joined: Jan 08, 2013
Posts: 6
Thanks for the reply.
But how can I make the initial value as null?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16055
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Siew Ling
Greenhorn

Joined: Jan 08, 2013
Posts: 6
Thanks very much, I have change the type to Integer and it works as what I want
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsf inputtext with empty value for integer type managed bean variable.