Reputation: 1870
I have a <p:inputText>
that I want to validate depending on the value from another bean property (one that does not hold the value of the <p:inputText>
).
Like if that bean property is true
validation passes, if it is false
validation fails.
How can I achieve that?
Upvotes: 3
Views: 7115
Reputation: 1109655
If you're talking about required="true"
, just let it bind to exactly that property.
<p:inputText ... required="#{not bean.property}" />
Or if you're talking about <f:validator>
or <f:validateXxx>
, just let its disabled
attribute bind to exactly that property.
<p:inputText ...>
<f:validator ... disabled="#{bean.property}" />
</p:inputText>
Note that those attributes are actually evaluated during the form submit request (and thus not during the form display request). So if your bean is request scoped, you'd need to make sure that the property is properly preinitialized during (post)construction.
Upvotes: 4