How to get current index of ui:repeat tag in a backing bean

4.4k Views Asked by At

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

1

There are 1 best solutions below

0
Kishor Prakash On

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){
...
}