[jsr-314-open-mirror] [jsr-314-open] Repetitive calls to FacesContext.getCurrentInstance() from listeners of system events

Leonardo Uribe lu4242 at gmail.com
Tue May 25 02:14:31 EDT 2010


Hi

Reviewing some stuff, it was notice that the FacesContext instance is not
passed when event processing occur, so every time a system event should be
processed, a call to FacesContext.getCurrentInstance() should be done in
almost all cases.

Below there are one example based on myfaces code (removed non relevant
code):

public class HtmlStylesheetRenderer extends Renderer implements
    ComponentSystemEventListener
{

    public void processEvent(ComponentSystemEvent event)
    {
        UIComponent component = event.getComponent();
        FacesContext facesContext = FacesContext.getCurrentInstance();
        facesContext.getViewRoot().addComponentResource(facesContext,
                    component, "head");
    }
    ......
}

It could be good to pass the current facesContext (note the code in
Application.publishEvent receive it as param), to prevent those unnecessary
calls and enhance code performance. In theory it is possible to cache
facesContext object on listeners suscribed using
UIViewRoot.subscribeToViewEvent() because those listeners are not saved (but
maybe not because if the same view is used on portlet....), but that's not
possible on ComponentSystemEventListener instances.

I'll open an issue for this one.

regards,

Leonardo Uribe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jsr-314-open-mirror/attachments/20100525/43b1b740/attachment-0002.html 


More information about the jsr-314-open-mirror mailing list