Search in sources :

Example 1 with EditableValueHolderAttachedObjectTarget

use of javax.faces.view.EditableValueHolderAttachedObjectTarget in project primefaces by primefaces.

the class CompositeUtils method invokeOnDeepestEditableValueHolder.

/**
 * Attention: This only supports cc:editableValueHolder which target a single component!
 *
 * @param context
 * @param composite
 * @param callback
 */
public static void invokeOnDeepestEditableValueHolder(FacesContext context, UIComponent composite, final ContextCallback callback) {
    if (composite instanceof EditableValueHolder) {
        callback.invokeContextCallback(context, composite);
        return;
    }
    BeanInfo info = (BeanInfo) composite.getAttributes().get(UIComponent.BEANINFO_KEY);
    List<AttachedObjectTarget> targets = (List<AttachedObjectTarget>) info.getBeanDescriptor().getValue(AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY);
    if (targets != null) {
        for (int i = 0; i < targets.size(); i++) {
            AttachedObjectTarget target = targets.get(i);
            if (target instanceof EditableValueHolderAttachedObjectTarget) {
                List<UIComponent> childs = target.getTargets(composite);
                if (childs == null || childs.isEmpty()) {
                    throw new FacesException("Cannot not resolve editableValueHolder target in composite component with id: \"" + composite.getClientId() + "\"");
                }
                if (childs.size() > 1) {
                    throw new FacesException("Only a single editableValueHolder target is supported in composite component with id: \"" + composite.getClientId() + "\"");
                }
                final UIComponent child = childs.get(0);
                composite.invokeOnComponent(context, composite.getClientId(context), new ContextCallback() {

                    @Override
                    public void invokeContextCallback(FacesContext context, UIComponent target) {
                        if (isComposite(child)) {
                            invokeOnDeepestEditableValueHolder(context, child, callback);
                        } else {
                            callback.invokeContextCallback(context, child);
                        }
                    }
                });
            }
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) AttachedObjectTarget(javax.faces.view.AttachedObjectTarget) EditableValueHolderAttachedObjectTarget(javax.faces.view.EditableValueHolderAttachedObjectTarget) BeanInfo(java.beans.BeanInfo) UIComponent(javax.faces.component.UIComponent) FacesException(javax.faces.FacesException) EditableValueHolderAttachedObjectTarget(javax.faces.view.EditableValueHolderAttachedObjectTarget) ContextCallback(javax.faces.component.ContextCallback) List(java.util.List) EditableValueHolder(javax.faces.component.EditableValueHolder)

Aggregations

BeanInfo (java.beans.BeanInfo)1 List (java.util.List)1 FacesException (javax.faces.FacesException)1 ContextCallback (javax.faces.component.ContextCallback)1 EditableValueHolder (javax.faces.component.EditableValueHolder)1 UIComponent (javax.faces.component.UIComponent)1 FacesContext (javax.faces.context.FacesContext)1 AttachedObjectTarget (javax.faces.view.AttachedObjectTarget)1 EditableValueHolderAttachedObjectTarget (javax.faces.view.EditableValueHolderAttachedObjectTarget)1