1

I am a new in a primefaces and I have one problem.

In my xhtml file I have ui:repeat tag, and with his varStatus attribute I can get the current index:

<ui:repeat var="i" varStatus="status">  
   index: #{status.index}<br/>  
</ui:repeat>  

but I need get this value in bean, and I hope someone helps me

Pravitha V
  • 3,308
  • 4
  • 33
  • 51
Eldos Narbay
  • 319
  • 4
  • 12
  • 1
    Possible duplicate of [Facelets repeat Tag Index](https://stackoverflow.com/questions/5562214/facelets-repeat-tag-index) – Adonis Jul 20 '17 at 08:59
  • Several things: 1, this is not PF related, 2, there are so many ways to get an index in the bean that you have to be way more specific. The 'answer' below is one of them, but if you need some sort of 'selection', maybe anyther component is better. And do you really need to get the index to the server or do you need to get the object. – Kukeltje Jul 20 '17 at 12:30

1 Answers1

3

There are many ways from which you can pass values to @ManagedBean from your Facelet.

One of which is: you can pass the index to your ManagedBeans action method using either h:commandButton or h:commandLink

Example:

Facelet:

<ui:repeat var="i" value="#{mBean.iList}" varStatus="status">
  <h:commandLink action="#{mBean.action1(status.index)}" value="index: #{status.index}">
       <f:ajax></f:ajax>
  </h:commandLink><br/>
</ui:repeat>

ManagedBean:

public void action1(Integer selectedIndex){
...
}
Kishor Prakash
  • 8,011
  • 12
  • 61
  • 92