• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RichFaces 4 h:inputText allow only numbers?

 
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this, it´s work well:



But this not allow a click on the backspace button, in case the user make a mistake.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic