[ 
https://issues.apache.org/jira/browse/MYFACES-2737?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Leonardo Uribe resolved MYFACES-2737.
-------------------------------------

    Fix Version/s: 1.1.8-SNAPSHOT
                   1.2.9-SNAPSHOT
                   2.0.1-SNAPSHOT
       Resolution: Fixed

With this hack we are saving a lot of calls. There is one call to 
FacesContext.getCurrentInstance() per each ValueBinding/ValueExpression that it 
is rendered. I attached the final patch and committed it on all branches.

> Cache FacesContext on UIComponentBase instances
> -----------------------------------------------
>
>                 Key: MYFACES-2737
>                 URL: https://issues.apache.org/jira/browse/MYFACES-2737
>             Project: MyFaces Core
>          Issue Type: Improvement
>          Components: JSR-314
>    Affects Versions: 2.0.0
>            Reporter: Leonardo Uribe
>            Assignee: Leonardo Uribe
>             Fix For: 1.1.8-SNAPSHOT, 1.2.9-SNAPSHOT, 2.0.1-SNAPSHOT
>
>         Attachments: MYFACES-2737-1.patch, MYFACES-2737-jsf11.patch, 
> MYFACES-2737-jsf12.patch, MYFACES-2737-jsf20.patch
>
>
> Right now, the implementation of UIComponentBase.getFacesContext() is this:
>     @Override
>     protected FacesContext getFacesContext()
>     {
>          return FacesContext.getCurrentInstance();
>     }
> I think it is possible to create a variable like this:
>     private transient FacesContext _facesContext;
> and change the current implementation to:
>     void setCachedFacesContext(FacesContext facesContext)
>     {
>         _facesContext = facesContext;
>     }
>     @Override
>     protected FacesContext getFacesContext()
>     {
>         if (_facesContext == null)
>         {
>             return FacesContext.getCurrentInstance();
>         }
>         else
>         {
>             return _facesContext;
>         }
>     }
> Then we do this on methods like processXXX, encodeXXX (not on encodeAll), 
> visitTree and invokeOnComponent:
>     @Override
>     public void processDecodes(FacesContext context)
>     {
>         try
>         {
>             setCachedFacesContext(context);
>  
>              /*...... do what is required ........*/
>         }
>         finally
>         {
>             popComponentFromEL(context);
>             
>             setCachedFacesContext(null);
>         }
> In few words, set and release temporally the variable while those operations 
> are executed. This change will reduce the amount of calls to 
> FacesContext.getCurrentInstance() without side effects, because we are 
> caching only on safe places and enclosing everything in a try finally block.
> If no objections I'll commit this code soon.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to