Java 怎么查找JSF父NamingContainer

2019年8月15日21:18:05Java 怎么查找JSF父NamingContainer已关闭评论 124 856字阅读2分51秒

1.简介

Java 怎么查找JSF父NamingContainer?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

 
import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import java.util.Collection;

public class Main{
    static UIComponent findParentNamingContainer(UIComponent component,
            boolean returnRootIfNotFound) {
        UIComponent parent = component.getParent();
        if (returnRootIfNotFound && parent == null) {
            return component;
        }
        while (parent != null) {
            if (parent instanceof NamingContainer) {
                return parent;
            }
            if (returnRootIfNotFound) {
                UIComponent nextParent = parent.getParent();
                if (nextParent == null) {
                    return parent; 
                }
                parent = nextParent;
            } else {
                parent = parent.getParent();
            }
        }
        return null;
    }
}

 
继续阅读
编程十万个怎么办