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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -