I need to validate a length of the value held by a UIInput
component only if the value of that UIInput
component is either null
or an empty.
The length validator - <f:validateLength>
should be skipped / bypassed, in case the value is null
or empty.
I have tried the following approach with no success.
<p:inputTextarea id="address" autoResize="false" value="#{testManagedBean.address}" maxlength="1000" minQueryLength="10" cols="35" rows="7">
<f:validateLength minimum="5" maximum="1000" disabled="#{empty testManagedBean.address}"/>
</p:inputTextarea>
<p:message for="address" display="both" showSummary="false"/>
<p:commandButton value="Submit" actionListener="#{testManagedBean.action}"/>
The bean:
@ManagedBean
@ViewScoped
public final class TestManagedBean implements Serializable
{
private String address;
private static final long serialVersionUID = 1L;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void action() {
System.out.println("action() called.");
}
}
This field - "address" is actually optional but if some users provide an input then, it should contain minimum of five characters in length.
EDIT:
I'm using disabled="#{empty param['form:address']}"
to disable the validator, when the UIInput
component has a null or empty value (not to dig further for a better way as this works anyway).