Question

I need a PrimeFaces input component, to get/set an amount of cash, that means a Decimal with 2 digits after the floating point.

I tried using inputMask, like

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

But I can't find some way to set a mask that accepts:

  1. 1 or more arithmetic values before floating point
  2. Optionally, a floating point "."
  3. 0 to 2 arithmetic values after the floating point

For Example, some valid inputs would be:

  1. 1234.56
  2. 1234.5
  3. 2.8
  4. 120
  5. 120.00

Any ideas to get this input in an efficient way?

Was it helpful?

Solution

A regular expression was the best way I've found so far

<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" />

OTHER TIPS

you can use Client Side Validation tag visit link

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

There are so may example that can help you. i think your problem will be resolved by these two tag

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

and

<p:clientValidator /> 

tell if not work.

Now i got exactly what you want. you want only two digit after "." The Prime Faces extensions are provide such type of checks. Go throw the link

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

it will sure help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top