Search code examples
jsfactionlisteneridentifiercommandbutton

Identify clicked p:commandButton in actionListener method


I'm tyring to get clicked button id in the action listener method.

This is my xhtml code:

<p:commandButton id="submitButton" value="Delete" action="#{student.xxx()}"
                 actionListener="#{student.UserActionListener(e)}"/>

This is my function for event handling in which I want to get id of a clicked button:

public void  UserActionListener (ActionEvent e) {
    System.out.println("the button id");
}

How is it possible to obtain id of submit button in action listener method?


Solution

  • Use e.getComponent()

    .......
    import javax.faces.event.ActionEvent;
    
    public class ........{
    
        public String buttonId; 
    
        public void  UserActionListener (ActionEvent e) {
            System.out.println(e.getComponent().getClientId());
    
        }
    }