jsf 2 - Multiple actionlisteners in JSF -


i want use multiple action listener set state of 2 backing beans before further processing

1st way:

<p:commandbutton process="@this" >    <f:attribute name="key" value="#{node.getidtestgroup()}" />    <f:actionlistener binding="#{testcontroller.nodelistener}" /> <f:actionlistener binding="#{testdevicegroupcontroller.preparecreate}" /> </p:commandbutton> 

it give exception:

warning: /testgroup/list.xhtml @26,88 binding="#{testcontroller.nodelistener()}": method nodelistener not found javax.el.elexception: /testgroup/list.xhtml @26,88 binding="#{testcontroller.nodelistener()}": method nodelistener not found

2nd way:

<p:commandbutton process="@this" >     <f:attribute name="key" value="#{node.getidtestgroup()}" />     <f:actionlistener binding="#{testcontroller.nodelistener(event)}" />     <f:actionlistener binding="#{testdevicegroupcontroller.preparecreate(event)}" /> </p:commandbutton> 

event null on nodelistener , preparecreate methods

how correct?

i see facilitate traditional approach of guess-how-it-works-using-bare-intuition-and-random-associations-then-act-surprised :-)

f:actionlistener lets add whole object observer, not arbitrary method. can either use type attribute specify class name (it instantiated jsf) or binding attribute give instance of object created (not method!). object must implement javax.faces.event.actionlistener.

your second try (testdevicegroupcontroller.preparecreate(event)) wrong on many levels, crux methods called not handle action, create actionlistener instance.

you have couple of options:

  • the sanest one: make method calls each of target methods. since on different beans, can inject 1 other.
  • if doesn't work you, can create method creates listener object.

like this:

public actionlistener createactionlistener() {     return new actionlistener() {         @override         public void processaction(actionevent event) throws abortprocessingexception {             system.out.println("here have both event object, , access enclosing bean");         }     }; } 

and use this:

<h:commandbutton>     <f:actionlistener binding="#{whateverbean.createactionlistener()}"/>             </h:commandbutton> 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -