Validate double number

UI Components for JSF
Post Reply
rchiu5hk
Posts: 32
Joined: 29 Jun 2015, 03:50

17 Feb 2017, 10:58

Dear all,

I have below code for inputting number of hours. But I does not know why when I input "11A" or "88**(((**%" and then click submit, it will pass the validation but without saving.

Code: Select all

<p:inputText required="true" requiredMessage="#{esMessage['WARN.ESTTC3S5']}" id="txtHours" value="#{courseInfo.regHours}" style="width:500px"
converter="javax.faces.Double" converterMessage="#{esMessage['WARN.ESTTC3S5.DigitOnly']}">

<f:convertNumber pattern="#0.00" />

</p:inputText>

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

18 Feb 2017, 14:08

Why don't you make this way easier on yourself and use p:inputNumber like...

Code: Select all

<p:inputNumber id="txtHours" required="true" value="#{courseInfo.regHours}" decimalPlaces="0" minValue="0" maxValue="24"/>
In the example above it only take integer numbers and has a value of 0 to 24. You can obviously increase if you need more than 24 hours but the component won't even allow letters or special symbols to be entered and it will convert to a Double or whatever Number you have on the back end.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 61 guests