Reputation: 301
I want to know how to get an row index of a datable, my code is
<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>
I get the row index in the event of the selectOneMenu of the celleditor.
The method in the bean is :
public void seleccionarEstado(AjaxBehaviorEvent event) {
System.out.println(" *** seleccionarEstado *** ");
System.out.println("Index: "+oiu.getIndex());
}
and the object oiu is :
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
}
but I don't get the value of the row, it is null, Why?
Thanks
Upvotes: 0
Views: 1672
Reputation: 6580
This is not elegant but may solve your problem.
public void seleccionarEstado(AjaxBehaviorEvent event) {
String x = ((HtmlSelectOneMenu)event.getSource()).getClientId();
System.out.println(x.split(":")[2]);
}
Notice that x will return something like (names may vary since these ids are generated)
j_idt6:idDataTableItemArticulo:0:j_idt19
^^^
And you're interested in the index above.
Upvotes: 1