// Retrieve the current FaceletContext from FacesContext object
FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(
FaceletContext.FACELET_CONTEXT_KEY);
ValueExpression ve = null;
Behavior behavior = null;
if (_delegate.getBinding() != null)
{
ve = _delegate.getBinding().getValueExpression(faceletContext, Behavior.class);
behavior = (Behavior) ve.getValue(faceletContext);
}
if (behavior == null)
{
behavior = this.createBehavior(faceletContext);
if (ve != null)
{
ve.setValue(faceletContext, behavior);
}
}
if (behavior == null)
{
throw new TagException(_delegate.getTag(), "No Validator was created");
}
_delegate.setAttributes(faceletContext, behavior);
if (behavior instanceof ClientBehavior)
{
// cast to a ClientBehaviorHolder
ClientBehaviorHolder cvh = (ClientBehaviorHolder) parent;
// TODO: check if the behavior could be applied to the current parent
// For run tests it is not necessary, so we let this one pending.
// It is necessary to obtain a event name for add it, so we have to
// look first to the defined event name, otherwise take the default from
// the holder
String eventName = getEventName();
if (eventName == null)
{
eventName = cvh.getDefaultEventName();
}
if (eventName == null)
{
throw new TagAttributeException(_delegate.getEvent(),
"eventName could not be defined for client behavior "+ behavior.toString());
}
else if (!cvh.getEventNames().contains(eventName))
{
throw new TagAttributeException(_delegate.getEvent(),
"eventName "+eventName+" not found on component instance");