As described in this question I try to perform some field validation in a form on the backing bean side. For this I would like to access the violating fields to mark them. From searching the web there seem to be two ways to do this:
- store the components in the backing bean for access and use them in the JSF pages via the
binding
attribute. - Use standard value binding in the JSF pages and when needing access to a component from the bean, look it up via
UIViewRoot.findComponent(String id)
As far as I can see both ways have drawbacks: Component bindings blows up the backing bean with variables and getters/setters, some sites strongly discourage the use of component binding at all. In any case, a request scope is advised. On the other hand, findComponent() always traverses the tree, which may or may not be costly, right? (Plus, at the moment I can't find my component at all, but that is another problem)
Which would be the way to go? Are these interchangeable alternatives and if not, based on what criteria do you chose? Currently I just don't have enough insight to make a decent decision...