PrimeFaces p:accordionPanel inside ui:repeat 或 c:forEach [英] PrimeFaces p:accordionPanel inside ui:repeat or c:forEach
问题描述
我正在尝试创建多个 accordionPanel
.我试图将这个标签包含在重复元素中(例如 c:forEach
).accordionPanel
呈现良好,但我无法从一个选项卡切换到另一个选项卡.
I'm trying to create multiple accordionPanel
s.
I tried to include this tag inside repeat elements (e.g. c:forEach
).
The accordionPanel
is well rendered, but I'm unable to switch from one tab to another.
这些是我试过的一些代码:
These are some codes I tried:
<ui:repeat value="#{myBackingBean.myList}" var="o">
<p:accordionPanel dynamic="true" cache="true" multiple="true" widgetVar="accordion">
<p:tab title="Title 1">
#{o.data_one}
</p:tab>
<p:tab title="Title 2">
#{o.data_two}
</p:tab>
</p:accordionPanel>
</ui:repeat>
还有
<c:forEach items"${myBackingBean.myList}" var="o">
<p:accordionPanel dynamic="true" cache="true" multiple="true" widgetVar="accordion">
<p:tab title="Title 1">
#{o.data_one}
</p:tab>
<p:tab title="Title 2">
#{o.data_two}
</p:tab>
</p:accordionPanel>
</ui:repeat>
这两个代码都会生成一个 accordionPanel
列表,每个列表都有两个选项卡.但是我无法从一个选项卡切换到另一个选项卡:如果我单击一个选项卡,它既不会打开也不会关闭(最后一个 accordionPanel
除外).
Both of these codes produces a list of accordionPanel
s, each with two tabs.
But I'm unable to switch from one tab to another: If I click one tab it does not open nor close (except for the last accordionPanel
).
值得注意的是,如果我手动放置两个或更多 accordionPanel
(没有 JSF 循环),它们会起作用.
Noteworthy, if I put two or more accordionPanel
s by hand (without JSF loops) they works.
此外,当我尝试打开/关闭选项卡时,我已经检查了浏览器发送的请求.我拦截的请求是这样的:
Also, I've checked the requests the browser sends when I try to open/close a tab. The requests I intercept are like:
<?xml version="1.0" encoding="utf-8"?><partial-response><changes><update id="mainForm:tabView"><![CDATA[
// something that always use the id of the HTML tag of the _last_ accordionPanel
</update></changes></partial-response>
如何将
放入
或
以便我仍然可以切换 accordionPanel
的选项卡吗?
How can I put an <accordionPanel>
inside an <ui:repeat>
or <c:forEach>
so that I can still switch the accordionPanel
's tab?
推荐答案
当您将 p:accordion
放入 ui:repeat 时,这是
,当您像在代码中那样明确指定 widgetVar
的问题widgetVar
时,它将生成具有不同/动态 Id 但不会具有不同/动态 widgetVar
的 Accordion Panel 组件.
Its the problem with the widgetVar
when you put p:accordion
in ui:repeat
, it will generate Accordion Panel components with different/dynamic Ids but not with different/dynamic widgetVar
when you explicitly specify widgetVar
like you're doing in your code.
基本上是 Javascript 对象的名称,用于访问 p:accordion
的客户端 Api 函数.
Which is basically name to Javascript Object to access the Client side Api functions of p:accordion
.
所以如果你没有在任何地方使用 p:accordion
的 widgetVar
,移除 widgetVar
属性,然后 widgetVar
将动态生成.
So If you are not using that widgetVar
of p:accordion
s anywhere, Remove widgetVar
attribute, then the widgetVar
will be generated dynamically.
如果还想用widgetVar
,自己给动态名,例如:
If you still want to use widgetVar
, give dynamic name yourself, for example:
widgetVar="accordion_#{o.data_one}"
注意:我仅在 ui:repeat
上尝试了上述策略.
使用:Primefaces 3.5 和 JSF 2.1.13 及其对我有用.
这篇关于PrimeFaces p:accordionPanel inside ui:repeat 或 c:forEach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!