0

I'm dealing with a legacy code base and come across a situation when it's necessary to validate a field "fieldToValidate" if some other field "otherField" has some value (otherwise field is not validated). However the field "otherField" doesn't have a binding attribute. I can add a binding and then update code like this:

<h:inputTextarea id="fieldToValidate" value="#{MyBean.fieldToValidate}" 
required="#{MyBean.otherField != 'special_value'}" />

However there is a plenty of places where validation should be added and I don't want to modify backing beans. Is there a way to implement validation without adding "binding"?

Validation with some JS library is not a option.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
robert
  • 496
  • 4
  • 18

1 Answers1

3

You do not necessarily need to bind it to a bean property. Just omit the MyBean. part to bind it to the view scope directly.

<h:selectOneMenu binding="#{otherField}" ... />
...
<h:inputTextarea ... required="#{otherField != 'special_value'}" />

See also:

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