Get row number in p: dataTable of dynamic element

I am wondering how to get the line number of an element inside <p:dataTable>.

<p:dataTable id="userDataTable" value="#{bean.rows}" rowIndexVar="rowIndex">
    <p:column headerText="RowCounter">
        <p:commandLink id="row#{rowIndex+1}" actionListener="#{bean.getRows}">
            <h:outputText value="Show Row #{rowIndex+1}" />
        </p:commandLink>
    </p:column>
</p:dataTable>

Bean:

public void getRows(ActionEvent ae) {                   
    System.out.println(ae.getComponent().getId().toString());
}

Always prints row1, no matter what click <p:commandLink>. What am I missing?

+5
source share
1 answer

, id JSF . , #{rowIndex} . , id, #{rowIndex} 0. , , , : JSTL JSF2 Facelets... ? , <p:commandLink>, . HTML ( !).

, id="row". . JSF ( HTML, ). , , , , , . . commandLink dataTable?

, :

Integer rowIndex = (Integer) ae.getComponent().getNamingContainer().getAttributes().get("rowIndex");

UIComponent#getNamingContainer() , , UIData, , , rowIndex. , :

UICommand commandLink = (UICommand) ae.getComponent();
UIData dataTable = (UIData) commandLink.getNamingContainer();
Integer rowIndex = dataTable.getRowIndex();
+3

All Articles