select a record of a p: datatable using a p: remoteCommand

1

I have a p:datatable with n records, among these a field with a p:inputText , when you double click on it, call a p:remoteCommand that executes a method of managedBean .

The problem is that in the method I extract the record of where the event originated, but it does not bring me the correct record, it always brings me the last record, please help me.

Deputy 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";  

    }
    
asked by Isaac De La Cruz 12.07.2017 в 18:53
source

1 answer

0

By parts:

  • p:remoteCommand all it does is define a JavaScript function that invokes a method on the server. The information on which row is selected, which button calls the JS, etc. it just does not ship.

  • Since p:remoteCommand defines a JS function, putting it within the datatable all you do is that your code defines the same function once for each row. It is not very useful. Get it out of datatable

  • To pass parameters to p:remoteCommand , it is done like this:

    <h:inputText value="#{item.pk.ordenrepId}"
        ondblclick="commandDobleClicOrdenrepId([{name:'idEdit', value:'#{item.pk.ordenrepId}')"
        readonly="true" style="border:0;background-color: #fff" 
        title="Dar doble clic desea ver la pre-factura actual."/>    
    

    and in the managed bean you pick it up with a @ManagedProperty

    @ManagedProperty("#{param.idEdit}")  
    private String id;
    
  • p:remoteCommand makes a Ajax request. That is, it will execute the code you say 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 a commandLink or commandButton , that's what they are for and that all users will be able to identify the first one.

answered by 12.07.2017 / 20:40
source