Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p:inputText size attribute doesn't limit allowed text length

Tags:

primefaces

I am using p:inputText and the size attribute does not effectively limit the number of allowed characters in the field:

<p:inputText id="limitedField" title="Limited Field" 
        size="16" required="true"
        styleClass="plainInput"
        value="#{entity.limitedField}" />

First of all, the user is physically allowed to enter more 16 characters. Secondly, when they do, instead of a graceful message displayed to the user in the front end they entered an invalid value, which should be a provision of the JSF framework error, they get a generic exception:

Caused by: java.sql.SQLException: ORA-12899: value too large for column "MYSCHEMA"."MY_TABLE"."LIMITED_FIELD" (actual: 22, maximum: 16)

I looked into the generated HTML and there is indeed a size attribute given to the text input but it is not effective:

<input id="..." name="limitedField" type="text" size="16" title="Limited Field"" aria-required="true" class="..." />

I thought simply setting the size attribute would prevent invalidly sized data to even be attempted to be written in the DB but apparently not. How do I fix this?

like image 223
amphibient Avatar asked May 01 '26 11:05

amphibient


1 Answers

Try maxlength attribute

maxlength="16"

like image 110
JusTinMan Avatar answered May 05 '26 09:05

JusTinMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!