在 f:facet 中查找一个或多个组件 - 它是否按设计工作?

发布于 2024-10-29 04:47:07 字数 1522 浏览 1 评论 0原文

我的页面上有一个自定义组件,里面有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请爱~陌生人 2024-11-05 04:47:07

好的,在 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)

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

Ok, found the answer in the method addComponent from ComponentSupport. 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)

All facets children are included into a UIPanel automatically, so that my code works fine.

贩梦商人 2024-11-05 04:47:07

我不知道它是在哪里指定的,但我在官方Java EE教程中找到了一条注释。

来自 Java EE 6 教程(包括 JavaServer Faces 2.0):

Facets 只能有一个孩子,所以
如果需要的话,需要 h:panelGroup 标签
将多个组件分组
在 f:facet 内

也许将参数包装在 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):

Facets can have only one child, so an
h:panelGroup tag is needed if you want
to group more than one component
within an f:facet

Maybe wrapping your params inside an h:panelGroup will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文