I’m creating a MenuItem dynamically and I want to add a custom listener when the MenuItem is clicked.
I’ve tried adding addActionListener and setActionListener but neither of these get called when the link is clicked.
It appears that there is a List called “listeners” attached to MenuItem (I can see this when debugging a MenuItem setup with the listener statically). Any idea how to add the listener correctly?
They needs to be created and added as follows (copied from one of my previous answers):
…where
#{bean.actionListener}actually exists and is declared like follows in the backing bean class associated with the managed bean namebean:More importantingly, you need to give any dynamically created
UICommand(andUIInput) component in question a fixed ID as well, else it will get an autogenerated ID which may cause that JSF cannot locate/correlate it during the apply request values phase.Thus, do so as well: