Reputation: 131
In a datatable, I have to validate the input as currency. When I enter the value after deleting the $ sign, the input component throws an error.
<p:column>
<f:facet name="header">
<p:outputLabel value="REC REVENUE" />
</f:facet>
<p:inputText id="RERVN" styleClass="RERVN"
value="#{segmentSetup.userSegmentTypesMap['RERVN'].segmentValues[rank].rangeMinValue}"
disabled="#{!segmentSetup.userSegmentTypesMap['RERVN'].selected || (rank==fn:length(segmentSetup.ranks)) }"
validator="#{segmentSetup.validateRanges}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" currencySymbol="$" type="currency" />
</p:inputText>
<p:message for="RERVN" />
</p:column>
When I enter a value without the dollar sign, I get this validation error.
Upvotes: 3
Views: 1372
Reputation: 1109062
Put the $
apart from the input and use a normal number converter.
$<p:inputText ...>
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</p:inputText>
You can if necessary use CSS to reposition the $ visually back into the input element. Here's a kickoff example in plain HTML/CSS:
<div class="currency"><span>$</span><input /></div>
with
.currency span { position: absolute; margin: 5px 2px; }
.currency input { padding-left: 5px; }
Upvotes: 4