c12
c12

Reputation: 9827

Primefaces dataTable with embedded commandLink

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...
}

Upvotes: 2

Views: 16247

Answers (1)

Matt Handy
Matt Handy

Reputation: 30025

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
 }

Upvotes: 4

Related Questions