On 8/8/05, Sean Schofield <[EMAIL PROTECTED]> wrote:
> I have another possible solution for this validation problem.  It
> involves going back to your original answer where you suggested the
> Process Validations phase as the logical place for this type of
> activity to occur.
> 
> My main problem was access to other components so I could see their
> submitted value.  As I mentioned I am not thrilled with relying on the
> structure of the component tree in my validation logic, yet I really
> need access to these components.  I started thinking about the binding
> attribute but that limits you to binding a single pair of components
> only.

Although access to the other components by navigating the component
tree is guaranteed to work, I take your point that it makes the logic
of this "check" type validator more fragile.  Here's a technique to
consider that might alleviate the issue somewhat:

* Use the "binding" attribute to bind all your input components to
  corresponding properties in the backing bean (Creator will do this
  for you automatically :-).

* Instead of implementing validators as separate classes, implement
  them as a method binding to a method in the same backing bean:

  <h:inputText binding="#{mybean.username}"
validator="#{mybean.checkBizRules}"/>

  which would bind to a method like this:

  public void checkBizRules(FacesContext context, UIComponent
component, Object value)
    throws ValidatorException;

Discerning viewers will note that this is exactly the same method
signature as the Validator.validate() method, except for the method
name.

Within checkBizRules(), you'll have access to the actual components by
name (that is, by the property names you bound them to) without having
to navigate the structure of the component tree.  You're guaranteed,
by virtue of the lifecycle, that all the submitted values have been
set first ... although you're not guaranteed that all the other
validators have fired yet.

> 
> My idea is to create a custom component that would extend UIInput but
> not generate any HTML when rendered.  This component could hold
> references to a Map of components that would bind to it using the
> binding attribute.  That way you could write validators for this
> "binding component" and have access to all of the components you need.
>  I haven't figured out the details (such as how the components would
> be keyed) but its a different approach that might yield something
> interesting.
> 
> What do you think?
> 

Hmm ... sort of along the lines of what <x:saveState> does for state
saving?  I think it might be simpler to use the explicit bindings
approach outined above.

> sean
> 

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to