How to make a Spinner that only accepts numbers in PrimeFaces?

3

I'm using PrimeFaces for a college project. How do I make "Spinner" not accept "Characters" only numbers?

Idade:
<p:spinner id="spinnerBasic"  max="120" value="#{spinnerController.number1}"/>
    
asked by anonymous 18.05.2014 / 01:19

1 answer

1

Good afternoon, you can solve this problem using javascript as below:

<script type="text/javascript">
   function onlyNumbers(data){
      data.value = data.value.replace(/[^0-9]/g,'');
   };
</script>

And in spinner use ( you can change the time of the call if you want, using another type of event ):

<p:spinner id="spinnerBasic"  max="120" value="#{spinnerController.number1}" onkeyup="onlyNumbers(this)" />
    
19.05.2014 / 19:06