在 f:facet 中查找一个或多个组件 - 它是否按设计工作?
我的页面上有一个自定义组件,里面有一个 Facet
<jtcomp:blockUI ...>
<f:facet name="events">
<f:param name="filtering" value="true"/>
<f:param name="sorting" value="true"/>
<f:param name="paging" value="true"/>
</f:facet>
...
</jtcomp:blockUI>
在渲染器类中我打算收集所有 UIParameter (f:param)。首先我得到的方面如下
UIComponent facet = blockUI.getFacet("events");
。现在我想我可以调用facet.getChildren()并迭代所有孩子。但我已经调试并发现只有当 f:facet 包含多个 f:param 组件时我才能做到这一点。如果它只有一个像这样的 f:param ,
<jtcomp:blockUI ...>
<f:facet name="events">
<f:param name="filtering" value="true"/>
</f:facet>
...
</jtcomp:blockUI>
上面的调用已经传递了这个组件。我的意思是,facet 是一个 UIParameter。因此,整个逻辑看起来像是
// collect all f:param
List<UIParameter> uiParams = new ArrayList<UIParameter>();
if (facet instanceof UIParameter) {
// f:facet has one child and that's f:param
uiParams.add((UIParameter) facet);
} else if (facet != null && facet.getChildren() != null) {
// f:facet has no or more than one child
for (UIComponent kid : facet.getChildren()) {
if (kid instanceof UIParameter) {
uiParams.add((UIParameter) kid);
}
}
}
预期的 JSF 行为还是只是 Mojarra 错误(我正在使用 Mojarra 2.1.0-b02)?我知道,在 JSF2 之前,f:facet 中只允许有一个组件。如果只有一个子组件可用,也许他们仍然会检查它并且不会实例化 FacetsMap。 FacetsMap 不再包含所有子组件,而是将子组件作为切面自绑定到父组件。
你怎么认为?我在 JSF 规范中找不到任何内容。预先感谢您的回复!
I have on my page a custom component with a Facet inside
<jtcomp:blockUI ...>
<f:facet name="events">
<f:param name="filtering" value="true"/>
<f:param name="sorting" value="true"/>
<f:param name="paging" value="true"/>
</f:facet>
...
</jtcomp:blockUI>
In the renderer class I intend to gather all UIParameter (f:param). At first I get the facet as follows
UIComponent facet = blockUI.getFacet("events");
Well. Now I thought I can call facet.getChildren() and iterate then over all childs. But I have debugged and figured out I can only do it if f:facet contains more than one f:param components. If it only has one f:param like this
<jtcomp:blockUI ...>
<f:facet name="events">
<f:param name="filtering" value="true"/>
</f:facet>
...
</jtcomp:blockUI>
the call above delivers already this component. I mean, facet is an UIParameter. Therefore, the entire logic looks like
// collect all f:param
List<UIParameter> uiParams = new ArrayList<UIParameter>();
if (facet instanceof UIParameter) {
// f:facet has one child and that's f:param
uiParams.add((UIParameter) facet);
} else if (facet != null && facet.getChildren() != null) {
// f:facet has no or more than one child
for (UIComponent kid : facet.getChildren()) {
if (kid instanceof UIParameter) {
uiParams.add((UIParameter) kid);
}
}
}
Is it an expected JSF behavior or just a Mojarra bug (I'm using Mojarra 2.1.0-b02)? I know, that before JSF2 only one component was allowed to be inside of f:facet. Maybe they still check it and don't instantiate FacetsMap if only one child component is available. Instead of FacetsMap containing all child components there is then the child component self bound as a facet to the parent component.
What do you think? I could nothing find in the JSF specification. Thanks in advance for your replies!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,在 ComponentSupport 的 addComponent 方法中找到了答案。 java
所有方面子项都会自动包含到 UIPanel 中,因此我的代码可以正常工作。
Ok, found the answer in the method addComponent from ComponentSupport. java
All facets children are included into a UIPanel automatically, so that my code works fine.
我不知道它是在哪里指定的,但我在官方Java EE教程中找到了一条注释。
来自 Java EE 6 教程(包括 JavaServer Faces 2.0):
也许将参数包装在
h:panelGroup
中会对您有所帮助。I don't know where it is specified but I found a comment in the official Java EE tutorial.
From the Java EE 6 tutorial (including JavaServer Faces 2.0):
Maybe wrapping your params inside an
h:panelGroup
will help you.