【发布时间】:2011-05-15 04:33:12
【问题描述】:
我正在构建一个自定义 UIComponent 并在其中添加元素(和其他库存 UIComponents)。组件渲染正常,但在 ViewRoot 中找不到。
假设我有:
ResponseWriter writer;
@Override
public void encodeBegin(FacesContext context) throws IOException {
writer = context.getResponseWriter();
writer.startElement("div", this);
writer.writeText("testing", null);
writer.writeAttribute("id", getClientId(context) + ":testDiv", null);
}
@Override
public void encodeEnd(FacesContext context) throws IOException {
writer.endElement("div");
}
添加为:
<x:myUiComponent id="myComponent" />
这渲染正常,但是我无法从 ViewRoot 中找到组件或其子 div:
context.getViewRoot().findComponent("myComponent"); // returns null
context.getViewRoot().findComponent("myComponent:testDiv"); // returns null
findComponent("myComponent:testDiv"); // called within the custom component, throws java.lang.IllegalArgumentException?
当我尝试将其他 UIComponents 添加为我的自定义组件的子组件时,同样的问题也存在 - 它们成功呈现,但是由于我的自定义组件本身并不存在,因此无法从组件树中找到。
将组件放入组件树的技巧是什么?
编辑:调整标题以更好地反映问题。
【问题讨论】:
标签: jsf jsf-2 uicomponents