Thursday, March 24, 2011

<af:setPropertyListener> fails when used with <af:showPopupBehavior> for a button's action !

I've discussed a possible reason for <af:setPropertyListener> not to work on <af:popup> when used along with childCreation="deferred" in one of my previous post. In today's post, I'm again taking you back to yet another unsupported usage of <af:popup> :-). In this case, the popup triggering part looks like as shown in the following page snippet. Apparently, here the expectation is to initialize 'someVariable' before showing the popup.

 <af:commandButton text="Show Popup" id="cb6">  
 <af:setPropertyListener from="#{'something'}" to="#{pageFlowScope.someVariable}" type="action"/>  
 <af:showPopupBehavior popupId="p1"/>  
 </af:commandButton>  

However the above fails to initialize the property before showing the popup. Why?

The reason is well documented under 'Cancels Client Events' of the <af:showPopupBehavior> tag doc.

The showPopupBehavior tag cancels the client event defined by the triggerType. Canceling the client event will prevent delivery to the server. This is significant for action events raised by command family components because the server-side action listeners will be ignored. All actionListener method bindings and associated action listeners will not be invoked when the triggerType of "action" is used.

In a nutshell the action event gets cancelled by the showPopupBehavior tag, so your property setter doesn't gets invoked. However there are a couple of workarounds...

1. Try using popupFetchListener for initializing the popup content(instead of <af:setPropertyListener> tag).
 <af:popup id="p2" contentDelivery="lazyUncached"   
     childCreation="deferred"   
     popupFetchListener="#{TestBean.popupFetchAction}" ...  

2. Try opening the popup programmatically (instead of using showPopupBehavior tag). Examples can be found under the tag doc for af:popup. You can safely use <af:setPropertyListener> to initialize properties in this approach.

3. Trigger the showPopupBehavior for 'click' instead of 'action'.
<af:showPopupBehavior popupId="p1" triggerType="click" />
Underlying theory is that 'click' and an 'action' do not cancel each other.

7 comments:

Spyros Doulgeridis said...

Nice post as usual!
Although in my opinion 1 is not a solution. Reason is if control is disabled and its triggerType="click", it will still raise the component (which in this case obviously we do not want).
Check http://adfhowto.blogspot.com/2010/11/troubleshooting-afshowpopupbehavior.html

Spyros

Jobinesh said...

Thanks Spyros for the input,I was not aware of that. That makes me to drag the first point to the last place :)

Naresh said...

Hey thanks man.
Naresh

Jobinesh said...

Welcome!

Life with out Technology ?! said...

Thanks..that help to remove the confusion.

Sunil said...

Jobinesh,
In my trial I found that triggerType should always be set to "action" if we use "popupFetchListener". And that's what we wanted. Thanks.

subbu said...

Thanks Jobinesh for the post...It helped me in the similar use case.