Reputation: 127
Is there any way of writing an inputText which is only accepting digits and also in the #,###.00 pattern format for inputting a currency number in JSF ? (using PrimeFaces will be more appreciated)
Thanks...
Upvotes: 5
Views: 41371
Reputation: 8219
Adding additional helpful not listed answer for this question :
Simply you can use primefaces extension tag inputNumber
:
https://www.primefaces.org/showcase/ui/input/inputNumber.xhtml
Upvotes: 1
Reputation: 570
This below code is working
<script>
<![CDATA[
function isNumber(event) {
if (event) {
var charCode = (event.which) ? event.which : event.keyCode;
if (charCode < 48 || charCode > 57)
return false;
}
return true;
}
]]>
</script>
<p:inputText id="money" onkeydown="return isNumber(event);" />
to erase key available
<script>
<![CDATA[
function isNumber(event) {
if (event) {
var charCode = (event.which) ? event.which : event.keyCode;
if ((charCode < 48 || charCode > 57) && charCode!=8 && charCode!=46)
return false;
}
return true;
}
]]>
</script>
<p:inputText id="money" onkeydown="return isNumber(event);" />
Upvotes: 1
Reputation: 61
Check this link
Here says you can use:
<p:inputMask value="# {maskController.date}" mask="99/99/9999"/>
I never used PrimeFaces before but i've used JSF. If you dont want to use javascript, you need to use a convert tag inside of the inputText tag.
<h:inputText id="money" required="true">
<f:convertNumber maxFractionDigits="2"
groupingUsed="true"
currencySymbol="$"
maxIntegerDigits="4"
type="currency"/>
</h:inputText>
PD: RegEx is another option. RegEx means Regular Expression. It is a way to check if something like an string matches with a rule. You can use in jsf with the RegEx Validator.
Upvotes: 4