JSF 2获取索引行数据表



我想知道如何获得一个数据表的行索引,我的代码是

<p:dataTable 
    id="idDataTableItemArticulo" 
    var="articuloEspecificado" 
    value="#{ordenIngresoBean.oiu.articuloEspecificadoModel}"
    paginator="true" 
    rows="5"  
    rowIndexVar="row" 
    paginatorPosition="bottom"
    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
    rowsPerPageTemplate="5"  
    emptyMessage="Lista de Proveedores vacia" 
    editable="true" 
    editMode="cell">  
    <p:column 
        width="25px;" 
        style="text-align:center;">
        <f:facet name="header">
            <h:outputLabel value="Nro"/>
        </f:facet>
        <h:outputText value="#{row+1}" />
    </p:column>
    <p:column width="70px;" style="text-align:center;">  
        <f:facet name="header">  
            <h:outputText value="Nro de Serie" />  
        </f:facet>  
        <p:inputText 
            id="idInNroSerie" 
            value="#{articuloEspecificado.numeroSerie}" 
            size="15" 
            onclick="this.select();"
            required="#{not empty param[bndGuardar.clientId]}" 
            requiredMessage="Ingrese Serie">
            <p:clientValidator event="keyup"/>
        </p:inputText>  
        <p:message for="idInNroSerie" display="text"/>
    </p:column>  
    <p:column width="70px;" style="text-align:center;" >  
        <f:facet name="header">  
            <h:outputText value="Codigo de Barras" />  
        </f:facet>  
        <p:inputText 
            value="#{articuloEspecificado.nroCodigoBarras}" 
            size="15" 
            onclick="this.select();"/>  
    </p:column>
    <p:column width="70px;" style="text-align:center;" headerText="Estado">  
        <p:cellEditor>
            <f:facet name="output">
                <h:outputText value="#{articuloEspecificado.estadoUsoArticulo.nombre}"/>
            </f:facet>
            <f:facet name="input">
                <h:selectOneMenu value="#{articuloEspecificado.codigoEstado}" style="width:100%">
                    <f:selectItems 
                        value="#{ordenIngresoBean.oiu.lstEstadoUsoArticulo}" 
                        var="eua" 
                        itemLabel="#{eua.nombre}" 
                        itemValue="#{eua}" />
                    <p:ajax 
                        event="change" 
                        listener="#{ordenIngresoBean.seleccionarEstado}">
                        <f:setPropertyActionListener 
                            value="#{row}" 
                            target="#{ordenIngresoBean.oiu.index}" />
                    </p:ajax>
                </h:selectOneMenu>
            </f:facet>
        </p:cellEditor>
    </p:column>
</p:dataTable>

我在单元格程序的selectOneMenu事件中获得行索引。

bean中的方法是:

public void seleccionarEstado(AjaxBehaviorEvent event) {
    System.out.println(" *** seleccionarEstado *** ");
    System.out.println("Index: "+oiu.getIndex());
}

,对象为:

public class OrdenIngresoUtil implements Serializable { 
private boolean lstArticuloEspecificadoVacia;
private Integer cantidad;
private Integer idSerie;
private Integer indexArticuloAlmacen;
private Integer index;
private String nroSerie;
private String numero; ..... more attributes and setter and getter
}

但我没有得到行值,它是空的,为什么?

谢谢

这不是很优雅,但可以解决您的问题。

public void seleccionarEstado(AjaxBehaviorEvent event) {
    String x = ((HtmlSelectOneMenu)event.getSource()).getClientId();        
    System.out.println(x.split(":")[2]);
}

请注意,x将返回类似于(由于生成这些id,名称可能会有所不同)

j_idt6:idDataTableItemArticulo:0:j_idt19
                              ^^^

您对上面的索引感兴趣

最新更新