Entering price lists for entering money (exactly 2 digits after floating point)

I need a PrimeFaces input component to get / set the amount of cash, which means a decimal number with two digits after the floating point.

I tried using inputMask, for example

<p:inputMask value="#{moneyBean.amount}" mask="999.99"/>

But I can’t find a way to set a mask that can limit:

  • 1 or more arithmetic values ​​before a floating point
  • Optional floating point " . "
  • 0 to 2 arithmetic values ​​after floating point

For example, some valid inputs are:

  • 1234.56
  • 1234.5
  • 2.8
  • 120
  • 120.00

Any ideas for effectively entering this parameter?

+4
2

,

<p:inputText id="numInput" value="#{val.value}" required="true"
    label="#{val.title}" validatorMessage="Not valid Number">
    <p:ajax event="change" process="@form" update=":edit_main" />
    <f:validateRegex pattern="^[-+]?[0-9]*\.?[0-9]{1,2}+$" />
</p:inputText>
<p:message for="numInput" />
+2

http://www.primefaces.org/showcase/ui/csvEvent.jsf

, . ,

<f:validateDoubleRange minimum="5.5" maximum="8.5" /> 

<p:clientValidator /> 

, .

, . "." Prime Faces extensions .

http://www.primefaces.org/showcase-ext/sections/inputNumber/advanceUsage.jsf

.

0

Source: https://habr.com/ru/post/1537712/


All Articles