jsf - 在 f :facet - does it work as designed? 中找到一个或多个组件

标签 jsf jsf-2

我的页面上有一个自定义组件,里面有一个 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() 然后遍历所有 child 。但是我已经调试并发现我只能在 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,而是将子组件自绑定(bind)为父组件的构面。

你怎么看?我在 JSF 规范中找不到任何东西。提前感谢您的回复!

最佳答案

好的,在 ComponentSupport 的方法 addComponent 中找到了答案。 java

/**
* Add the child component to the parent. If the parent is a facet,
* check to see whether the facet is already defined. If it is, wrap the existing component
* in a panel group, if it's not already, then add the child to the panel group.
* If the facet does not yet exist, make the child the facet.
*/
public static void addComponent(FaceletContext ctx, UIComponent parent, UIComponent child)

所有方面的 child 都会自动包含在 UIPanel 中,因此我的代码可以正常工作。

关于jsf - 在 f :facet - does it work as designed? 中找到一个或多个组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5511851/

相关文章:

java - 未在 @RequestScoped ManagedBean 中获取请求参数

java - 将用户的备注作为字符串传递给 java bean

jsf - :choose with multiple c:when - fall-through switch

css - 如何使用 JSF 嵌入 CSS 背景图像链接?

spring - Primefaces <p :ajax update ="@all"/> doesn't work

JSF 复合库名称和子文件夹

java - JSF网页包含

java - Primefaces 5.0 数据滚动和分页

jsf-2 - 如何在primefaces中使用RequestContext?

xhtml - "PWC3999: Cannot create a session after the response has been committed"