I have one p:datatable
with n records, among these a field with a p:inputText
, when you double click on it, it calls a p:remoteCommand
that executes a method of a managedBean
.
The problem is that in the method I extract the record from where the event originated, but it does not bring me the correct record, it always brings me the last record, please someone help me.
Attached code:
<p:column style="width:40px;padding-left:1px;text-align:center;">
<f:facet name="header">
<h:outputText value="Id Orden" />
</f:facet>
<p:remoteCommand name="commandDobleClicOrdenrepId" action="#{ordenTrabajoController.dobleClicOrdenrepId}" partialSubmit="true" />
<h:inputText value="#{item.pk.ordenrepId}" ondblclick="commandDobleClicOrdenrepId();" readonly="true" style="border:0;background-color: #fff"
title="Dar doble clic desea ver la pre-factura actual."/>
</p:column>
ManagedBean
public String dobleClicOrdenrepId(){
SeOrdenRep seOrdenRep = (SeOrdenRep) getListadoOrdenes().getRowData();//AQUI ME DA SIEMPRE EL ULTIMO REGISTRO
return "form.jsf";
}
Part by part:
p:remoteCommand
all it does is define a JavaScript function that calls a method on the server. The information of which row is selected, which button calls the JS, etc. it just doesn't ship.Since
p:remoteCommand
it defines a JS function, by putting it inside thedatatable
only thing you do is that your code defines the same function once for each row. It is not very useful. take it out of thedatatable
To pass parameters to
p:remoteCommand
, do it like this:and in the managed bean you pick it up with a
@ManagedProperty
p:remoteCommand
makes an Ajax request . That is, it will execute the code you tell it to, but it will not redirect you to another page.Using "double click on a text field" to send to a different page is, to put it mildly, very unintuitive. Use an
commandLink
orcommandButton
, that's what they are for and that all users will be able to identify at first.