[
https://issues.apache.org/jira/browse/MYFACES-2737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872080#action_12872080
]
Martin Marinschek commented on MYFACES-2737:
--------------------------------------------
Hi Leonardo,
I _definitely_ like this approach - no spec changes necessary. Way cool!
It was that simple, and I just didn't see it ;). Neither did any of the cs-JSF
team and EG members involved - just great.
best regards,
Martin
> 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
> Attachments: MYFACES-2737-1.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.