0

I would like to call a method of my controller when clicking on the MenuItem and then be redirected to the corresponding page.

My XHTML:

<h:form>
    <p:tabMenu activeIndex="#{param.i}">
        <p:menuitem value="Past Transactions" actionListener="#{transactionListController.findAllTx()}" outcome="/transaction-past.xhtml">
            <f:param name="i" value="2" />
        </p:menuitem>
    </p:tabMenu>
</h:form>   

My Bean:

@Named
@RequestScoped
public class TransactionListController {

    @Inject
    private TransactionService txService;

    @Inject
    private TransactionListModel txListModel;

    public void findAllTx() {
        System.out.println("find All");

        List<Transaction> allTx = txService.findAllTx();
        txListModel.setTxList(allTx);
    }
}

I am already using findAllTx() with a commandButton elsewhere and it works fine. How do I call it when clicking on the MenuItem ? All the examples I found showed the ActionListener as a solution.

Tim
  • 3,910
  • 8
  • 45
  • 80
  • Thanks, still I am not sure where the error is. I changed the to but the method is not called. I am grateful for any pointer – Tim Jul 15 '16 at 06:58
  • I am still getting the warning "The form component needs to have a UIForm in its ancestry". I know it's not an error, but still. – Tim Jul 15 '16 at 07:20
  • Please take a step back an find a good JSF tutorial. Your error IS in the duplicate, did you read it? – Kukeltje Jul 15 '16 at 07:53
  • I have about 30 open tabs with tutorials, SO Questions and other JSF Docs. As you can see, I am fairly new to this - so please don't expect me to understand everything right away. To the untrained eye, it is not as obvious as you may think. To answer your question: Yes I have read it, not I did not find it yet. I thought this is what SO was for. – Tim Jul 15 '16 at 08:01
  • Sorry, I forgot to mention that I had already changed the
    to along with the change
    – Tim Jul 15 '16 at 08:18

0 Answers0