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.