3

I have a PrimeFaces carousel in which I would like to display an editable inputTextArea. Unfortunately it seems p:carousel has no attribute to get the current index, like rowIndexVar in p:dataGrid.

What are other solutions for rendering only the current 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>
ballidanse
  • 157
  • 5
  • 13

1 Answers1

6

<p:carousel> implements UIData (like <p:dataTable>, <p:dataGrid>, etc). That component class has a rowIndex property. You could just grab it directly.

First bind the <p:carousel> component to an unique variable name in EL (absolutely don't bind it to a bean property!):

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

The component instance will elsewhere in same page be available via #{carousel}. You can then just access its rowIndex property like so #{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>

Unrelated to the concrete problem, this is fishy. Why not just binding the textarea value to the currently iterated row instead of to the bean?

<p:carousel ... var="item">
    <p:inputTextarea value="#{item.text}" />
    ...
</p:carousel>
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for your answer. It seems the attribute binding is not defined any more in the component carousel in recent versions of primefaces. I am using primefaces 5.3. Concerning your 2nd suggestion, I have to modify the textarea value. – ballidanse Nov 06 '15 at 11:12
  • I have no idea what you're talking about. Are you talking about false errors/warnings emitted by the editor you're using which prevented you from actually trying to run the code? Just ignore'n'run it and update/replace the code editor. As to modifying the textarea value, it's still possible that way, so I'm not understanding the problem here either. – BalusC Nov 06 '15 at 11:14
  • Actually it works ! Yes, I was talking about the NetBeans error. Why is there no binding attribute in the Carousel class ? http://www.primefaces.org/docs/api/5.3/ There is a "bindings" inherited attribute, but no "binding". – ballidanse Nov 06 '15 at 11:29
  • For the second part, I thought every modified value had to be saved in a managed bean property ? – ballidanse Nov 06 '15 at 11:33
  • 1) Documentary/IDE bug. 2) It's already a managed bean property. No need to duplicate/flatten/expand it. – BalusC Nov 06 '15 at 11:51
  • Indeed, I didn't see things like that. Thanks a lot – ballidanse Nov 06 '15 at 14:11