2

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?

amphibient
  • 29,770
  • 54
  • 146
  • 240
  • 1
    possible duplicate of [Difference between "maxlength" & "size" attribute in html?](http://stackoverflow.com/questions/25247565/difference-between-maxlength-size-attribute-in-html) – Kukeltje Jun 08 '15 at 20:26

1 Answers1

6

Try maxlength attribute

maxlength="16"

JusTinMan
  • 110
  • 2
  • IMO, having two different attributes for size and maxlength, while i understand the difference, is one of those nuances that overcomplicates matters more than does it benefit from "sophistication". i think there should just be one setting and it means how many characters you can put in the field. things should be kept simple – amphibient Jun 08 '15 at 20:02
  • 3
    Then create a new custom/composite component. Not everybody wants it that way. I have ui's where, for making it have not all kinds of inputs with different physical size, I give them the same size but with a different max length. Complain at the w3c – Kukeltje Jun 08 '15 at 20:17