Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 限制复合构件的放置_Jsf_Composite Component - Fatal编程技术网

Jsf 限制复合构件的放置

Jsf 限制复合构件的放置,jsf,composite-component,Jsf,Composite Component,是否有可能以这样一种方式声明复合组件,即只将其放置在某些标记中 例如: <span> <n:myComponent/> </span> 将是非法的,而: <div> <n:myComponent/> </div> 将是合法的。不是在构建期间,而是在渲染期间,您可以检查组件的同级 public void encodeChildren(FacesContext context) { List&

是否有可能以这样一种方式声明复合组件,即只将其放置在某些标记中

例如:

<span>
    <n:myComponent/>
</span>

将是非法的,而:

<div>
    <n:myComponent/>
</div>


将是合法的。

不是在构建期间,而是在渲染期间,您可以检查组件的同级

public void encodeChildren(FacesContext context) {
    List<UIComponent> children = getParent().getChildren();
    // Loop over children until you find a child which equals to "this".
    // Then check if the previous and next sibling contains <span> and </span>.
    // ...

    if (valid) {
        super.encodeChildren(context);
    } else {
        throw new IllegalArgumentException("n:myComponent can't be placed inside <span>");
    }
} 
public子对象(FacesContext上下文){
List children=getParent().getChildren();
//在子对象上循环,直到找到一个等于“this”的子对象。
//然后检查上一个和下一个同级是否包含和。
// ...
如果(有效){
超级儿童(上下文);
}否则{
抛出新的IllegalArgumentException(“n:myComponent不能放在里面”);
}
} 

您可以在
UINamingContainer
实现中执行此操作,该实现作为

引用的
@FacesComponent
我是否可以直接对照
getParent()
进行检查?否,
getParent()
是最接近的父
UIComponent
实例。
不是完整的
UIComponents
,只是作为纯文本处理。它们显示为同一父级的同级
UIComponent
。如果它是
,那么您确实可以通过
getParent()
获得
。哦,我不知道
被视为纯文本。我用它们来演示。实际上,我想检查我是否是Primefaces组件库的
的孩子。我猜
是一个
UIComponent
,所以检查
getParent()
应该可以。