【发布时间】:2014-06-18 14:58:33
【问题描述】:
我们的 xhtml 中有以下结构:
<ui:repeat ...>
...
<h:selectOneMenu ...>
...
<p:ajax event="change" update="@parent:@parent" process="@parent:@parent" />
</h:selectOneMenu>
</ui:repeat ...>
在事件处理程序中,我们可以访问代表 selectOneMenu 的 UiComponent。我们可以导航到父级,代表 ui:repeat。在查看孩子时,我希望在网页上看到所有可见的 selectOneMenu,但我只看到一个。触发更改事件的那个。
如何访问 ui:repeat 组件下的同级组件?
动机:
我们基本上创建了一个分组表。 IE。一个表,它被分组为具有属于一起的数据的部分。上面的代码创建了一个组。必须为组中的一个条目选择 selectOneMenu 中的某些值。因此,当一个值更改时,我们必须访问同一组中的所有条目以检查约束是否已完成,否则在违规字段上显示错误消息。
它在浏览器中的外观:
table: there is another outer repeat for creating the contents of this table
..group 1: content of each group is created by the ui:repeat
....row with selectOnMenu
....row with selectOnMenu
....row with selectOnMenu
....row with selectOnMenu
..group 2: content of each group is created by the ui:repeat
....row with selectOnMenu
....row with selectOnMenu
....row with selectOnMenu
....
带有 selectOnMenu 的行
它在事件处理程序中的样子:
UiRepeat --> SelectOneMenu(exactly one)
【问题讨论】:
-
每个
h:selectOneMenu都需要绑定到一个服务器端模型,由其value属性给出。您还没有足够的能力,或者您还需要专门获取 UIComponent 实例吗?你在 UIComponent 中寻找什么? -
我们需要 UIComponent,因为我们想将验证消息附加到它。我还想了解我们只看到一个组件是否正常,或者我们是否正在做一些特殊/错误的事情,只是为了更好地理解 JSF。
-
Ajax 请求能够发送不同的表单部分。这就是您在
f:ajax execute=""或p:ajax process=""属性中定义的内容。由于它们默认为@this,因此只有当前组件 (h:selectOneMenu) 被发送到处理,因此将其切换到@form可能是解决您问题的关键。顺便说一句,您是否出于任何特定原因使用h:selectOneMenu和p:ajax?你应该使用f:ajax如果 vanilla JSF 或p:selectOneMenu如果想用 Prime 来做这一切。 -
@XtremeBiker process 属性应该涵盖我认为的所有 selectOneMenus。我更新了问题中的代码。混合 h: 和 p: 的原因不是很具体。 p:selectOneMenu 看起来真的很丑。
-
然后使用
f:ajax。这是 JSF 组件的标签。
标签: jsf-2 primefaces