PrimeFaces p:accordionPanel inside ui:repeat or c:forEach

浪子不回头ぞ 提交于 2019-12-08 09:39:12

问题


I'm trying to create multiple accordionPanels. 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>

And also

<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>

Both of these codes produces a list of accordionPanels, 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).

Noteworthy, if I put two or more accordionPanels 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>

How can I put an <accordionPanel> inside an <ui:repeat> or <c:forEach> so that I can still switch the accordionPanel's tab?


回答1:


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.

Which is basically name to Javascript Object to access the Client side Api functions of p:accordion.

So If you are not using that widgetVar of p:accordions anywhere, Remove widgetVar attribute, then the widgetVar will be generated dynamically.

If you still want to use widgetVar, give dynamic name yourself, for example:

widgetVar="accordion_#{o.data_one}" 

Note: I tried the above strategy with only on ui:repeat.
Using:Primefaces 3.5 and JSF 2.1.13 and its working for me.



来源:https://stackoverflow.com/questions/21581695/primefaces-paccordionpanel-inside-uirepeat-or-cforeach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!