I'm using PrimeFaces 3.4 with PrimeFaces Mobile 0.9.3. I specified maxlength in the inputText attribute, but it is not being rendered across in the HTML. My code:
<p:inputText id="price" value="#{bean.price}" styleClass="r-align"
type="number" maxlength="9" validator="priceValidator"/>
Later I found that when I remove the "type" attribute from the tag, max length works. Does anyone know why this is the case?
There is a workaorund you have to play with "maxValue":
For example, if your max length is: 8 so you should put max value as : 99999999 which is a number with 8 digits.
That's simply because
maxlength
attribute is not supported on the HTML5<input type="number">
element, so it's reasonable to assume that PrimeFaces renderer won't emit it.Instead, you should be using
min
andmax
attributes. Theoretically, you should be set withHowever, this didn't work for me. It didn't render the
max
(nor themin
) attribute altogether. This is in turn likely an oversight in the PrimeFaces component. Your best bet is to report it as an issue to PrimeFaces guys.In the meanwhile, you can work this around by providing a custom renderer like this which basically adds the
min
andmax
attributes to the list of pass thru attributes:which you can get to run by registering it as follows:
Note that passing through custom JSF component attributes will be natively supported in the upcoming JSF 2.2, which allows among others HTML5
data-*
attribute freedom.See also:
Set
maxlength
andMaxValue
to set the maxlength for Primefaces inputnumber