0

Currently i have a field that takes in a telephone number.

It performs a length validation without fail. What i really want is there to be length validation only when a value is input, and no validation when there is no value. How can i accomplish this?

<p:inputText id="corporateTel" label="#{labelResource.telephone}">
    <f:validateLength minimum="5" maximum="20" />
</p:inputText>
Oh Chin Boon
  • 23,028
  • 51
  • 143
  • 215

1 Answers1

3

This is already the default behaviour. Your problem is caused elsewhere. Perhaps you used an int instead of Integer or String, so that it defaults to 0 instead of null. Or perhaps you used an Integer while running the webapp on Tomcat/JBoss wherein the default Apache EL implementation would implicitly coerce it to 0 instead of null. You can turn it off by adding the following VM argument:

-Dorg.apache.el.COERCE_TO_ZERO=false

Or use String instead of Integer. This is also a more appropriate data type for phone numbers as they may have a leading 0 which would otherwise be chopped off when using Integer.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555