Struggling BEA WLP fireCustomEvent in begin action
The begin action of a pageflow is not allowed to fire custom events. This post describes a possible workaround for this.
In several of our pages we have a content portlet in the left column along with some other portlets in the right column of the page. Among those right column pages is a related content portlet. This portlet will show content related to the content in the other portlet. Now we would like to build upon the netuix events firing a custom event from the content portlet that would be handled in the related content portlet. Name of the custom event is showcontentevent, the payload in the event is information of the content currently being viewed.
In the related content portlet we implemented a backing file to get the event and put in on the outer request with attribute name, <portlet_instance_label>_relatedcontent. The portlet_instance_label being the instance label of the related content portlet.
Problem: the begin action is not allowed to invoke PortletBackingContext.fireCustomEvent(...). The following warning is written to the log
...<Warning> <netuix> <BEA-423371> <Illegal state ('PRE_RENDER') for call to ....PortletBackingContext.fireCustomEvent ...
Now, how to get rid of that warning ? The begin action does not have a handlePostBack so using a backing file is not possible. But, events are allowed to be fired in an event handler.
I made a pageflow event handler on the content portlet. Set it up to listen on the begin action, added an Invoke Pageflow Action that invoked a new action publishEvent.
I implemented the publishEvent action forwarding to the same JSP as the begin action. The method also added the payload to the outer request with attribute name
<portlet_instance_label>_relatedcontent using the instance label of the related content portlet.
Next I added a Fire Custom Event in the event handler firing the showcontentevent.
Result:
The event is fired without warning and the receiving portlet will find its payload on the request as expected.
Comments
Even if there is written a warning invoking fireCustomEvent in the begin action, the event seems to fire.
This method assumes the two portlets share the outer request, meaning there probably would be problems with this method for remote portlets. For events without payload the method should work.
update:
Could it be that fireCustomEvent in begin action is not recommended as it could create some problem in some weird configuration. And in a plain portal the event will work as expected? Something like the warning for redirect in begin action.
- keep on struggling -


8 comments:
Could it be that fireCustomEvent in begin action is not recommended as it could create some problem in some weird configuration.
That's right. Begin actions are run somewhat late in the rendering processing, and if your event handler tried to do something that changed some portal state, bad things could happen. But in your case, the warning is certainly overzealous.
Your workaround sounds correct, but maybe a little indirect. I wonder if it would work to have your original begin action put the form in the request as you describe, and then the target portlet could listen directly to the begin action on the source portlet (you can qualify the event handler to only listen to a certain portlet). That might be a little cleaner.
To be honest I did not think of the possibility for the portlet to listen to the begin action on another portlet.
However as there are several actions in the content portlet firing the showcontentevent I would use this solution to keep the related content portlet cleaner.
Thanks for the comment.
I now see that the post did not mention that there are other actions firing the event - sorry about that one.
This article also applies to WLP 9.2.
731857047
http://www.1063029483.com
[url=http://www.486263790.com]486263790[/url]
146458922
Post a Comment