3

How can I invoke a method from backing bean before popup panel shows?

<h:commandButton value="Call the popup" action="#{bean.doSomething}" >
    <rich:componentControl target="popup" operation="show" />
</h:commandButton>

<rich:popupPanel id="popup" modal="true" resizeable="true" onmaskclick="#{rich:component('popup')}.hide()">
   ...
</rich:popupPanel>

In this case doSomething() method doesn't invoke.

Ventsislav Marinov
  • 594
  • 1
  • 6
  • 14

3 Answers3

6

Nest a4j:ajax in the commandButton or use a4j:commandButton. These two components have an oncomplete attribute where you could put a code that opens the popup dialog like this:

<a4j:commandButton value="Call the popup" action="#{bean.doSomething}" oncomplete="#{rich:component('popup')}.show()">
</a4j:commandButton>

This will perform an ajax request when the button is clicked and will open the popup when the request is finished.

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
Adrian Mitev
  • 4,722
  • 3
  • 31
  • 53
  • I might add that if you want to rerender the contents of the popup as a result of the action (lazy-loading data for instance), you'll want to stick a render attribute on the a4j:commandButton tag. – Tim Clymer May 31 '13 at 16:02
1

You could simply use f:ajax on successful response show the popup

Also See

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • Be a little more detailed about where to use f:ajax, if I use f:ajax before rich:componentControl the popup panel doesn't show. Do you mean to put f:ajax in rich:popupPanel? – Ventsislav Marinov Mar 17 '12 at 20:06
1

I think you should use an actionListener in this case. The action is used to change the view and I assume you just want to show the popup.

MAG, Milo

Milo van der Zee
  • 1,031
  • 11
  • 30
  • Negative. The purpose of the actionListener is to invoke a server-side code. What he wants/needs is to invoke client-side code (that shows the popup). – Adrian Mitev Mar 17 '12 at 21:26