Forums Register Login

RichFaces 4 h:inputText allow only numbers?

+Pie Number of slices to send: Send
I have a field in JSF2, I tried execute a validation in this way:




And thus:



However, my field only makes a validation and show me a message, I would like just the insertion of numbers, not Strings, this is possible ?



Is possible a insertion only of numbers ?

Thanks in advance for all !
+Pie Number of slices to send: Send
Ironically, the old IBM mainframe "dumb green screen" terminals had that ability, but not HTML GUIs.

I believe that HTML5 supports not only limiting input text, but also (on mobile devices), the intelligent selection of virtual keyboards (numeric keypad pop-up instead of a full text keyboard).

Unfortunately, RichFaces 4 is still stuck on HTML4, I believe, so that feature isn't available. The best you could do is attach a JavaScript to the keydown or keypress event of that control. Do a web search and you should be able to find examples. Look for "HTML numeric only input", since it's not specifically a RichFaces thing.
+Pie Number of slices to send: Send
I found this, it´s work well:



But this not allow a click on the backspace button, in case the user make a mistake.
+Pie Number of slices to send: Send
That's the idea.

What I recommend, however, over doing it as inline javascript is that you code that as a javascript function call. That way you can A) code longer, more complex logic (including backspace/Enter handling) B) recycle the code in the event you have other numeric-only controls and C) export the function text to an external ".js" file. Which is easier to use a browser's javascript debugger on.
+Pie Number of slices to send: Send
I finished using this function:



This work well in IE and Chrome, I don´t know why it´s not work well in firefox too, this function block the tab key in Firefox.

I found this post too:

HTML Text Input allow only Numeric input

Thanks Tim, Thanks for all.
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 9418 times.
Similar Threads
How can i reisize h:inputTex inside h:panelGrid ?
confused in converter
problem with Error message and Bean
Multipart request problem
How to retain selected value from dropdown list in same jsp page
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:09:27.