How can i make sure at conversion and validation phase during the JSF lifecycle that entered value in <h:inputText> contains alphabets only?
Thanks in advance.
You can use <f:validateRegex> for this.
<h:inputText id="input" value="#{bean.input}" validatorMessage="Please enter alphabets only">
<f:validateRegex pattern="[a-zA-Z]*" />
</h:inputText>
It accepts the same regex syntax as the Pattern class. Check its documentation. You can also use \p{Alpha} instead.
<f:validateRegex pattern="\\p{Alpha}*" />
Or if you're using bean validation (as confirmed by your question history), then you can also use #Pattern for this.
#Pattern(regexp="\\p{Alpha}*", message="Please enter alphabets only")
private String input;
Related
i 've been looking a lot about how to make my allows just number to be inserted inside , seems quite easy but it doesn't work in anyway.
I have this code :
<p:fragment id="thresoldPrice">
<h:inputText type="number"value="" disabled="#{!tradingFunnelCBean.tradingFunnelMBean.conditionalOrder}" styleClass="#{!tradingFunnelCBean.tradingFunnelMBean.conditionalOrder ? '' : 'num-col'} middle-space">
<f:convertNumber pattern="#.####" integerOnly="true" maxFractionsDigit="4"/>
<p:watermark for="thresoldPrice"value="#{localizationBean.getMessageValue('EP3.GIMB.TRADINGFUNNEL.PRIVATE.LABEL.WATERMARK', languagePreferenceBean.selectedPreference)}" />
</h:inputText>
</p:fragment>
but it keeps accepting String values. i would also like to make the value inserted in this format "#.####" but the pattern attribute of the h:inputText doesn't make anything.
Any suggestion?
I try to check if an input text is a Integer or not. I have wrote this piece of code:
<h:inputText id="amount" value="#{receipt.amount}" required="true" converterMessage="error" requiredMessage="error" validatorMessage="error" >
<f:validateLongRange minimum="1" maximum="#{receipt.all}" />
<f:convertNumber IntegerOnly="true" />
</h:inputText>
and it is working but in one case if I put for example "1a" it converts me this to "1". How can I check this in JSF? I would like to see a message if input is incorrect. I have made validation in my bean and everything worked but I have to do in JSF. Could anybody explain how to set maximum="#{receipt.all} correct? If I put in this way I have a zero. I try to refres this input but it didn't work.
I want to restrict my <p:inputMask> with only letters and numbers without giving any size (max-legth) limit. I tried to use mask attribute but when I use mask attriibute it gives a max-length for my inputMask. Could you please help me to solve this issue ?
Sample Code :
<p:inputMask value="#{gercekKrediBasvuruDetayGirisView.kisi.ticariHarfSeri}"
required="true" mask="***"
requiredMessage="#{msg['GercekKrediBasvuruTuketiciMaliBilgiler.belgeSeriNull']}"
/>
If your input does not have to be <p:inputMask> and can be <h:inputText> or <p:inputText> then the easiest way to go would be to use it with regex:
<h:inputText id="inputField" value="#{backingbean.username}" validatorMessage="Value does not match pattern.">
<f:validateRegex pattern="^[a-zA-Z0-9]+$" />
</h:inputText>
<h:message for="inputField" />
If you only allow lower case letters go with ^[a-z0-9]+$.
<p:inputMask> is designed for somewhat stricter validation than only letters and numbers.
I am using PrimeFaces 3.5 with JSF 2.0. I have fields, which is used to enter an amount in the format like 100000.00. sometimes users enter the amounts including commas like 15,234.00 and when they submit the page, it cuts off the numbers after comma and pass only 15. Kindly suggest?
I am using the below converter and validator to validate the field.
<p:inputText value="#{myBean.EstLossAmt }" converterMessage="Please enter only numeric values" id="estimatedLoss">
<f:convertNumber pattern="####.00"/>
<f:validateDoubleRange minimum="0.00" maximum="999999999.99"/>
</p:inputText>
it should allow upto 30 digits before decimal and atleast 1 , atmost 2 digits after decimal
If you use JSF 2.0 you can use the regex-validator tag:
<h:inputSecret id="password" value="#{user.password}">
<f:validateRegex pattern="add your pattern here" />
</h:inputSecret>
If you are still on JSF 1.x I think you have to write your own custom validator by creating a class that implements javax.faces.validator.Validator interface. Here is a good tutorial how to achieve this.
Here in this example is the solution i suggest for validating double:
<h:inputText id="someField" value="#{yourBean.doubleValue}">
<f:convertNumber minFractionDigits="2" />
<f:validateDoubleRange minimum="1" maximum="30"/>
</h:inputText>
Use the attributes of the convertNumber tag to set the limits you need.