java-通过单击行中的按钮获取primefaces数据表中的行号

提问

如何通过单击某行中的按钮来获取Primefaces(2.2)数据表中的行号?
我需要将此数字传递给具有hint()函数的javascript代码.

1个解决方案

使用WidgetVar.selection,但在这种情况下,我手动使用行选择,然后单击按钮->糟糕的情况.

< p:column>
< p:commandButton id =“ someButton” value =“ Button”
      actionListener =“#{managedBean.someEvent}” onclick =“返回jsMethod(widgetVar.selection)” />
< / p:列>

谢谢!

最佳答案

您可以为此使用UIData#getRowIndex().

<p:dataTable binding="#{table}" ...>
    <p:column>
        <p:commandButton ... onclick="return jsMethod(#{table.rowIndex})" />
    </p:column>
</p:dataTable>