As the subject says: I'd like to be able to attach multiple action listeners to a <p:menuitem>, similar to how it is possible to attach multiple action listeners to a <p:commandbutton>. This is usually accomplished by adding the <f:actionlistener> tag to <p:commandbutton> multiple times instead of defining the "actionListener" attribute. It works with command buttons, but not with menu items. Any thoughts?
I'd like this to be available for PrimeFaces Mobile and Regular.
Attaching Multiple ActionListeners to p:menuitem
PrimeFaces 6.0 / JSF 2.2 Mojarra / GlassFish 4.1.1 / NetBeans 8.2
Why you need multiple actionListeners?Any specific reason?
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/
___________________
Sudheer Jonna
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/
___________________
Sudheer Jonna
Yes. In my app I need two action listeners: one listener that processes something specific for an entity (an entity controller) inside a ViewScoped managed bean, and a second listener that keeps track of visited pm:pages inside a SessionScoped bean. Works perfectly with a command button, but apparently not with a menu item.
PrimeFaces 6.0 / JSF 2.2 Mojarra / GlassFish 4.1.1 / NetBeans 8.2
Btw: here's a documented example of using multiple action listeners over on http://archive.oreilly.com/pub/a/onjava ... tml?page=3. Scroll down to "Using an Action Listener Method or Instance". The article states that "you can attach as many ActionListener instances as you want to the component".
I'd imagine this to be true in PrimeFaces as well, but at least MenuItem does not function properly when using more than one action listener.
I'd imagine this to be true in PrimeFaces as well, but at least MenuItem does not function properly when using more than one action listener.
PrimeFaces 6.0 / JSF 2.2 Mojarra / GlassFish 4.1.1 / NetBeans 8.2
Ok. I found out that p:menuitem does in fact work properly with multiple action listeners. I made the mistake of not supplying the proper signature to the binding attribute. Here is an example of what it should look like:
Notice how there is next to the listener method name. I originally didn't have that. Now it works.
Code: Select all
<p:menuitem value="Generate UUID" update="@form">
<f:actionListener binding="#{indexBean.menuClickListener(event)}"/>
<f:actionListener binding="#{sessionBean.loggerListener(event)}"/>
</p:menuitem>
Code: Select all
(event)
PrimeFaces 6.0 / JSF 2.2 Mojarra / GlassFish 4.1.1 / NetBeans 8.2
Ok, so now I have a different issue: the ActionEvent inside the listener is null! However, if I use the actionListener attribute and omit the (event) after the listener name, the event is not null.
Can anybody please assist?
Can anybody please assist?
PrimeFaces 6.0 / JSF 2.2 Mojarra / GlassFish 4.1.1 / NetBeans 8.2
What you did by adding the (event) parameter to the actionListener in the EL, is make it match the method signature of the method in the actionListener on the java side (what is that methodSignature btw?). It does not mean that 'event' has an actual value (try what happens if you rename event in the call to 'bla'? Does it exhibit the same behaviour or does it throw errors?
-
- Information
-
Who is online
Users browsing this forum: No registered users and 26 guests