// Get the FacesContext
FacesContext context = FacesContext.getCurrentInstance();
// Look on the UIComponent for the CommandHandlers
LayoutElement desc = null;
List<Handler> handlers = (List<Handler>)
command.getAttributes().get(LayoutComponent.COMMAND);
if ((handlers != null) && (handlers.size() > 0)) {
// This is needed for components that don't have corresponding
// LayoutElements, it is also useful for dynamically defining
// Handlers (advanced and not recommended unless you have a good
// reason). May also happen if "id" for any component in
// hierarchy is not a simple String.
// No parent (null) or ComponentType, just pass (null)
desc = new LayoutComponent(
(LayoutElement) null, command.getId(), (ComponentType) null);
} else {
// Attempt to find LayoutElement based on command's client id
// "desc" may be null
String viewId = getViewId(command);
desc = findLayoutElementByClientId(
context, viewId, command.getClientId(context));
if (desc == null) {
// Do a brute force search for the LE
desc = findLayoutElementById(context, viewId, command.getId());
}
}
// If We still don't have a desc, we're stuck
if (desc == null) {
throw new IllegalArgumentException(
"Unable to locate handlers for '"
+ command.getClientId(context) + "'.");
}
// Dispatch the Handlers from the LayoutElement
desc.dispatchHandlers(context, COMMAND_EVENT_TYPE, event);
}