html – How to make a Spinner that only accepts numbers on PrimeFaces?

Question:

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

Idade:
<p:spinner id="spinnerBasic"  max="120" value="#{spinnerController.number1}"/>

Answer:

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 the spinner use ( you can change the call time if you want, using another type of event ):

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