2

I'm trying to embed a Primefaces commandLink and call an action listener from a link inside a column of a Primefaces dataTable. Is this not possible? The "Test" onclick alert gets fired but it never makes it to my bean's method.

<p:dataTable var="location" value="#{adminBean.locations}">  
        <p:column headerText="Options">  
            <p:commandLink value="delete" actionListener="#{admin.deleteLocation}" onclick="alert('test')"/>
        </p:column>    
    </p:dataTable>

bean code:

public void deleteLocation(ActionEvent e){
   //delete logic here...
}
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
c12
  • 9,557
  • 48
  • 157
  • 253
  • Possible duplicate of [commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated](https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value) – Kukeltje Nov 11 '17 at 07:30

1 Answers1

4

This is possible. Your actionListener should be called. Keep in mind that the p:commandButton uses ajax by default. So you should use the update attribute in order to define the components to be updated.

However, I don't know if this affects the actionListener. Did you try it with action instead of actionListener?

Here is an example how I got it working:

<p:commandLink action="#{spc.selectPatient(item)}"
               ajax="false"
               value="Open"/>

The bean method looks as follows:

 public String selectPatient(Patient p) {
    // do something
    // return some outcome
 }
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • I'll give yours a try but I also see this example...http://www.primefaces.org/showcase/ui/datatableRowSelectionByColumn.jsf – c12 May 16 '11 at 18:06