0

I am using an ActionListener to find out if a next button was pressed, I plan to have a previous button implemented later.

This is the xhtml

<h:commandLink styleClass="btn btn-info" id="tablePagerNext"
                            value="Next" actionListener="#{records.increnemt}">
                            <f:ajax render="dataTableRecords" />
                        </h:commandLink>

Now that is supposed to call my method here:

public void increnemt(ActionEvent e){
        System.out.println("The action taken was " + e.getComponent().getAttributes().get("action"));
    }

Where based on the action it will call an appropriate method (This just prints out The action taken was null). I know that in swing you can do

if(e.getSource == jButton){
 //do this
}else{}

in JSF there is a .getSource() what I am not sure of is what that source is based on the xhtml above. I am not really sure what I am looking for when the event fires.

Could someone clear this up for me?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Michael Miner
  • 964
  • 2
  • 17
  • 39
  • Possibly this post will clear up the doubt. http://stackoverflow.com/questions/9291647/faces-actionevent-getsource-always-null – Dheeraj Arora Aug 13 '14 at 21:06
  • 1
    Stop thinking the Swing way while searching a JSF solution. It'll only confuse you because Swing uses Java for both model and view and a starter easily mixes up the responsibilities of model and view. What you're trying to achieve more likely belongs in the view, thus in XHTML. Just state the concrete problem in the question instead of asking how to achieve a (wrong) solution, then we can propose a true JSF solution. Most likely you just need to declare the "do this" method in the `action` attribute. – BalusC Aug 13 '14 at 21:13
  • @BalusC I really wish I understood jsf in te first place. I was just thrown into it. All I have as a reference is what I have seen in swing. For this would you suggest having a separate handler for each button? That to me seems redundant. – Michael Miner Aug 14 '14 at 00:13
  • With "handler" you mean "method"? Why is that redundant? Why is a bunch of if-else statements better than a bunch of separate methods with each a clear name? – BalusC Aug 14 '14 at 17:20

1 Answers1

-1

As per my understanding you wanted to know which button was clicked (next or prev or whatever)

As per ActionEvent documentation you dont have any method to identify button uniquely. I wish you will research on f:param to set some value to cross check the same in controller bean method (increnemt).

prathap
  • 465
  • 7
  • 15