如何获取 PrimeFaces 轮播的当前索引?

How to get current index of a PrimeFaces carousel?

我有一个 PrimeFaces 旋转木马,我想在其中显示一个可编辑的 inputTextArea。不幸的是,p:carousel 似乎没有获取当前索引的属性,例如 p:dataGrid 中的 rowIndexVar。

仅呈现当前 inputTextarea 的其他解决方案是什么?

        <p:carousel value="#{infb.infos}" var="info" **rowIndexVar="status"** numVisible="2" >
                ......
                        <p:inputTextarea value="#{infb.textArea1}" rendered="#{status == 0 and infb.displayEditor}" />
                        <p:inputTextarea value="#{infb.textArea2}" rendered="#{status == 1 and infb.displayEditor}" />
                        <p:inputTextarea value="#{infb.textArea3}" rendered="#{status == 2 and infb.displayEditor}" />
                        <p:inputTextarea value="#{infb.textArea4}" rendered="#{status == 3 and infb.displayEditor}" />
                        <h:panelGrid rendered="#{infb.displayEditor}" columns="2">
                            <p:commandButton value="Save" action="#{infb.modifyInfoText(info)}" />
                            <p:commandButton value="Cancel" action="#{infb.cancelModifyInfoText(info)}"/>  
                        </h:panelGrid>
                 .....
        </p:carousel>

<p:carousel> 实现 UIData (like <p:dataTable>, <p:dataGrid>, etc). That component class has a rowIndex 属性。直接抓包就可以了

首先将<p:carousel>组件绑定到EL中唯一的变量名(absolutely don't bind it to a bean property!):

<p:carousel binding="#{carousel}" ...>

组件实例将通过 #{carousel} 在同一页面的其他地方可用。然后你可以像这样访问它的 rowIndex 属性 #{carousel.rowIndex}.

<p:carousel binding="#{carousel}" ...>
    <p:inputTextarea ... rendered="#{carousel.rowIndex eq 0}" />
    <p:inputTextarea ... rendered="#{carousel.rowIndex eq 1}" />
    <p:inputTextarea ... rendered="#{carousel.rowIndex eq 2}" />
    <p:inputTextarea ... rendered="#{carousel.rowIndex eq 3}" />
    ...
</p:carousel>

与具体问题无关,这是fishy。为什么不将 textarea 值绑定到当前迭代的行而不是绑定到 bean?

<p:carousel ... var="item">
    <p:inputTextarea value="#{item.text}" />
    ...
</p:carousel>