You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2012/05/22 12:57:57 UTC
svn commit: r1341400 - in /myfaces/core/trunk:
api/src/main/java/javax/faces/component/
impl/src/main/java/org/apache/myfaces/application/
impl/src/main/java/org/apache/myfaces/el/unified/resolver/
impl/src/main/java/org/apache/myfaces/view/facelets/ i...
Author: lu4242
Date: Tue May 22 10:57:55 2012
New Revision: 1341400
URL: http://svn.apache.org/viewvc?rev=1341400&view=rev
Log:
MYFACES-3550 [perf] minimize FacesContext.getCurrentInstance() calls part II
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewParameter.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/_UIParameter.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItem.java
myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItems.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/StateWriter.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ViewMetadataHandler.java
myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java
myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlLinkRendererBase.java
myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java Tue May 22 10:57:55 2012
@@ -1253,6 +1253,16 @@ public abstract class UIComponent
//moved to the static method
return UIComponent.isCompositeComponent(this);
}
+
+ boolean isCachedFacesContext()
+ {
+ return false;
+ }
+
+ // Dummy method to prevent cast for UIComponentBase when caching
+ void setCachedFacesContext(FacesContext facesContext)
+ {
+ }
/**
* Gets value of "javax.faces.HONOR_CURRENT_COMPONENT_ATTRIBUTES" parameter cached in facesContext.attributes
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java Tue May 22 10:57:55 2012
@@ -498,7 +498,16 @@ public abstract class UIComponentBase ex
try
{
setCachedIsRendered(null);
- boolean rendered = isRendered();
+ boolean rendered;
+ try
+ {
+ setCachedFacesContext(context);
+ rendered = isRendered();
+ }
+ finally
+ {
+ setCachedFacesContext(null);
+ }
setCachedIsRendered(rendered);
if (!rendered)
{
@@ -519,7 +528,17 @@ public abstract class UIComponentBase ex
this.encodeBegin(context);
// rendering children
- if (this.getRendersChildren())
+ boolean rendersChildren;
+ try
+ {
+ setCachedFacesContext(context);
+ rendersChildren = this.getRendersChildren();
+ }
+ finally
+ {
+ setCachedFacesContext(null);
+ }
+ if (rendersChildren)
{
this.encodeChildren(context);
} // let children render itself
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewParameter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewParameter.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewParameter.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewParameter.java Tue May 22 10:57:55 2012
@@ -262,6 +262,25 @@ public class UIViewParameter extends UII
return delegateRenderer;
}
+ @Override
+ protected FacesContext getFacesContext()
+ {
+ //In theory the parent most of the times has
+ //the cached FacesContext instance, because this
+ //element is purely logical, and the parent is the one
+ //where encodeXXX was invoked. But only limit the
+ //search to the closest parent.
+ UIComponent parent = getParent();
+ if (parent != null && parent.isCachedFacesContext())
+ {
+ return parent.getFacesContext();
+ }
+ else
+ {
+ return super.getFacesContext();
+ }
+ }
+
/**
* @author Simon Lessard (latest modification by $Author$)
* @version $Revision$ $Date$
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java Tue May 22 10:57:55 2012
@@ -1020,7 +1020,22 @@ public class UIViewRoot extends UICompon
try
{
// Actual event broadcasting
- source.broadcast(event);
+ if (!source.isCachedFacesContext())
+ {
+ try
+ {
+ source.setCachedFacesContext(context);
+ source.broadcast(event);
+ }
+ finally
+ {
+ source.setCachedFacesContext(null);
+ }
+ }
+ else
+ {
+ source.broadcast(event);
+ }
}
catch (Exception e)
{
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_UIParameter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_UIParameter.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_UIParameter.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_UIParameter.java Tue May 22 10:57:55 2012
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
@@ -51,6 +52,25 @@ abstract class _UIParameter extends UICo
// throw new UnsupportedOperationException();
}
+ @Override
+ protected FacesContext getFacesContext()
+ {
+ //In theory the parent most of the times has
+ //the cached FacesContext instance, because this
+ //element is purely logical, and the parent is the one
+ //where encodeXXX was invoked. But only limit the
+ //search to the closest parent.
+ UIComponent parent = getParent();
+ if (parent != null && parent.isCachedFacesContext())
+ {
+ return parent.getFacesContext();
+ }
+ else
+ {
+ return super.getFacesContext();
+ }
+ }
+
/**
* The value of this component.
*
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItem.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItem.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItem.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItem.java Tue May 22 10:57:55 2012
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
@@ -54,6 +55,25 @@ abstract class _UISelectItem extends UIC
// throw new UnsupportedOperationException();
}
+ @Override
+ protected FacesContext getFacesContext()
+ {
+ //In theory the parent most of the times has
+ //the cached FacesContext instance, because this
+ //element is purely logical, and the parent is the one
+ //where encodeXXX was invoked. But only limit the
+ //search to the closest parent.
+ UIComponent parent = getParent();
+ if (parent != null && parent.isCachedFacesContext())
+ {
+ return parent.getFacesContext();
+ }
+ else
+ {
+ return super.getFacesContext();
+ }
+ }
+
/**
* The initial value of this component.
*
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItems.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItems.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItems.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_UISelectItems.java Tue May 22 10:57:55 2012
@@ -18,6 +18,7 @@
*/
package javax.faces.component;
+import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFExclude;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
@@ -64,6 +65,25 @@ abstract class _UISelectItems extends UI
//throw new UnsupportedOperationException();
}
+ @Override
+ protected FacesContext getFacesContext()
+ {
+ //In theory the parent most of the times has
+ //the cached FacesContext instance, because this
+ //element is purely logical, and the parent is the one
+ //where encodeXXX was invoked. But only limit the
+ //search to the closest parent.
+ UIComponent parent = getParent();
+ if (parent != null && parent.isCachedFacesContext())
+ {
+ return parent.getFacesContext();
+ }
+ else
+ {
+ return super.getFacesContext();
+ }
+ }
+
/**
* The initial value of this component.
*
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java Tue May 22 10:57:55 2012
@@ -486,7 +486,7 @@ public class ApplicationImpl extends App
}
else
{
- createdComponent = createComponent(componentType);
+ createdComponent = createComponent(facesContext, componentType);
componentExpression.setValue(elContext, createdComponent);
}
@@ -509,7 +509,10 @@ public class ApplicationImpl extends App
// Like createComponent(ValueExpression, FacesContext, String)
UIComponent component = createComponent(componentExpression, context, componentType);
- _inspectRenderer(context, component, componentType, rendererType);
+ if (rendererType != null)
+ {
+ _inspectRenderer(context, component, componentType, rendererType);
+ }
return component;
}
@@ -1173,8 +1176,8 @@ public class ApplicationImpl extends App
try
{
Behavior behavior = (Behavior)behaviorClass.newInstance();
-
- _handleAttachedResourceDependencyAnnotations(FacesContext.getCurrentInstance(), behavior);
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ _handleAttachedResourceDependencyAnnotations(facesContext, behavior);
if (behavior instanceof ClientBehaviorBase)
{
@@ -1182,9 +1185,8 @@ public class ApplicationImpl extends App
String renderType = clientBehavior.getRendererType();
if (renderType != null)
{
- FacesContext ctx = FacesContext.getCurrentInstance();
- ClientBehaviorRenderer cbr = ctx.getRenderKit().getClientBehaviorRenderer(renderType);
- _handleAttachedResourceDependencyAnnotations(FacesContext.getCurrentInstance(), cbr);
+ ClientBehaviorRenderer cbr = facesContext.getRenderKit().getClientBehaviorRenderer(renderType);
+ _handleAttachedResourceDependencyAnnotations(facesContext, cbr);
}
}
@@ -1335,7 +1337,7 @@ public class ApplicationImpl extends App
*/
if (component == null)
{
- component = application.createComponent(UINamingContainer.COMPONENT_TYPE);
+ component = application.createComponent(context, UINamingContainer.COMPONENT_TYPE, null);
annotationsApplied = true;
}
}
@@ -1381,13 +1383,53 @@ public class ApplicationImpl extends App
checkNull(componentType, "componentType");
// Like createComponent(String)
- UIComponent component = createComponent(componentType);
+ UIComponent component = createComponent(context, componentType);
- _inspectRenderer(context, component, componentType, rendererType);
+ // A null value on this field is valid! If that so, no need to do any log
+ // or look on RenderKit map for a inexistent renderer!
+ if (rendererType != null)
+ {
+ _inspectRenderer(context, component, componentType, rendererType);
+ }
return component;
}
+ /**
+ * This works just like createComponent(String componentType), but without call
+ * FacesContext.getCurrentInstance()
+ *
+ * @param facesContext
+ * @param componentType
+ * @return
+ * @throws FacesException
+ */
+ private final UIComponent createComponent(FacesContext facesContext,
+ final String componentType) throws FacesException
+ {
+ checkNull(componentType, "componentType");
+ checkEmpty(componentType, "componentType");
+
+ final Class<?> componentClass = getObjectFromClassMap(componentType, _componentClassMap);
+ if (componentClass == null)
+ {
+ log.log(Level.SEVERE, "Undefined component type " + componentType);
+ throw new FacesException("Undefined component type " + componentType);
+ }
+
+ try
+ {
+ UIComponent component = (UIComponent)componentClass.newInstance();
+ _handleAnnotations(facesContext, component, component);
+ return component;
+ }
+ catch (Exception e)
+ {
+ log.log(Level.SEVERE, "Could not instantiate component componentType = " + componentType, e);
+ throw new FacesException("Could not instantiate component componentType = " + componentType, e);
+ }
+ }
+
@Override
public final UIComponent createComponent(final String componentType) throws FacesException
{
@@ -1766,7 +1808,7 @@ public class ApplicationImpl extends App
// Create a UIOutput instance by passing javax.faces.Output. to
// Application.createComponent(java.lang.String).
- UIOutput output = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
+ UIOutput output = (UIOutput) application.createComponent(context, UIOutput.COMPONENT_TYPE, null);
// Get the annotation instance from the class and obtain the values of the name, library, and
// target attributes.
@@ -2241,7 +2283,7 @@ public class ApplicationImpl extends App
{
// Create a UIOutput instance by passing javax.faces.Output. to
// Application.createComponent(java.lang.String).
- UIOutput output = (UIOutput) createComponent(UIOutput.COMPONENT_TYPE);
+ UIOutput output = (UIOutput) createComponent(context, UIOutput.COMPONENT_TYPE, null);
// Get the annotation instance from the class and obtain the values of the name, library, and
// target attributes.
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java Tue May 22 10:57:55 2012
@@ -78,6 +78,7 @@ public class NavigationHandlerImpl
private Map<String, Set<NavigationCase>> _navigationCases = null;
private List<String> _wildcardKeys = new ArrayList<String>();
+ private Boolean _developmentStage;
public NavigationHandlerImpl()
{
@@ -682,15 +683,34 @@ public class NavigationHandlerImpl
@Override
public Map<String, Set<NavigationCase>> getNavigationCases()
{
- FacesContext facesContext = FacesContext.getCurrentInstance();
- ExternalContext externalContext = facesContext.getExternalContext();
- RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
-
- if (_navigationCases == null || runtimeConfig.isNavigationRulesChanged())
+ if (_developmentStage == null)
+ {
+ _developmentStage = FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Development);
+ }
+ if (!Boolean.TRUE.equals(_developmentStage))
+ {
+ if (_navigationCases == null)
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ExternalContext externalContext = facesContext.getExternalContext();
+ RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
+
+ calculateNavigationCases(facesContext, runtimeConfig);
+ }
+ return _navigationCases;
+ }
+ else
{
- calculateNavigationCases(facesContext, runtimeConfig);
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ExternalContext externalContext = facesContext.getExternalContext();
+ RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
+
+ if (_navigationCases == null || runtimeConfig.isNavigationRulesChanged())
+ {
+ calculateNavigationCases(facesContext, runtimeConfig);
+ }
+ return _navigationCases;
}
- return _navigationCases;
}
private synchronized void calculateNavigationCases(FacesContext facesContext, RuntimeConfig runtimeConfig)
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java Tue May 22 10:57:55 2012
@@ -357,7 +357,7 @@ public class ViewHandlerImpl extends Vie
{
// Facelets specific hack:
// Tell the StateWriter that we're about to write state
- StateWriter stateWriter = StateWriter.getCurrentInstance();
+ StateWriter stateWriter = StateWriter.getCurrentInstance(context);
if (stateWriter != null)
{
// Write the STATE_KEY out. Unfortunately, this will
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java Tue May 22 10:57:55 2012
@@ -63,10 +63,20 @@ public final class FacesCompositeELResol
_scope = scope;
}
+ private static FacesContext facesContext(final ELContext context)
+ {
+ FacesContext facesContext = (FacesContext)context.getContext(FacesContext.class);
+ if (facesContext == null)
+ {
+ facesContext = FacesContext.getCurrentInstance();
+ }
+ return facesContext;
+ }
+
@Override
public Class<?> getCommonPropertyType(final ELContext context, final Object base)
{
- final FacesContext facesContext = FacesContext.getCurrentInstance();
+ final FacesContext facesContext = facesContext(context);
if (facesContext == null)
{
return null;
@@ -96,7 +106,7 @@ public final class FacesCompositeELResol
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext context, final Object base)
{
- final FacesContext facesContext = FacesContext.getCurrentInstance();
+ final FacesContext facesContext = facesContext(context);
if (facesContext == null)
{
return null;
@@ -126,7 +136,7 @@ public final class FacesCompositeELResol
@Override
public Class<?> getType(final ELContext context, final Object base, final Object property)
{
- final FacesContext facesContext = FacesContext.getCurrentInstance();
+ final FacesContext facesContext = facesContext(context);
if (facesContext == null)
{
return null;
@@ -155,7 +165,7 @@ public final class FacesCompositeELResol
@Override
public Object getValue(final ELContext context, final Object base, final Object property)
{
- final FacesContext facesContext = FacesContext.getCurrentInstance();
+ final FacesContext facesContext = facesContext(context);
if (facesContext == null)
{
return null;
@@ -184,7 +194,7 @@ public final class FacesCompositeELResol
@Override
public boolean isReadOnly(final ELContext context, final Object base, final Object property)
{
- final FacesContext facesContext = FacesContext.getCurrentInstance();
+ final FacesContext facesContext = facesContext(context);
if (facesContext == null)
{
return false;
@@ -213,7 +223,7 @@ public final class FacesCompositeELResol
@Override
public void setValue(final ELContext context, final Object base, final Object property, final Object val)
{
- final FacesContext facesContext = FacesContext.getCurrentInstance();
+ final FacesContext facesContext = facesContext(context);
if (facesContext == null)
{
return;
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Tue May 22 10:57:55 2012
@@ -724,7 +724,8 @@ public class FaceletViewDeclarationLangu
// Create a temporal tree where all components will be put, but we are only
// interested in metadata.
UINamingContainer compositeComponentBase
- = (UINamingContainer) context.getApplication().createComponent(UINamingContainer.COMPONENT_TYPE);
+ = (UINamingContainer) context.getApplication().createComponent(
+ context, UINamingContainer.COMPONENT_TYPE, null);
// Fill the component resource key, because this information should be available
// on metadata to recognize which is the component used as composite component base.
@@ -1880,7 +1881,7 @@ public class FaceletViewDeclarationLangu
ExternalContext extContext = context.getExternalContext();
Writer outputWriter = extContext.getResponseOutputWriter();
- StateWriter stateWriter = new StateWriter(outputWriter, 1024);
+ StateWriter stateWriter = new StateWriter(outputWriter, 1024, context);
try
{
ResponseWriter writer = origWriter.cloneWithWriter(stateWriter);
@@ -1987,7 +1988,7 @@ public class FaceletViewDeclarationLangu
}
finally
{
- stateWriter.release();
+ stateWriter.release(context);
}
}
catch (FileNotFoundException fnfe)
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/StateWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/StateWriter.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/StateWriter.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/StateWriter.java Tue May 22 10:57:55 2012
@@ -61,6 +61,11 @@ public final class StateWriter extends W
return (StateWriter)facesContext.getAttributes().get(CURRENT_WRITER_KEY);
}
+
+ static public StateWriter getCurrentInstance(FacesContext facesContext)
+ {
+ return (StateWriter)facesContext.getAttributes().get(CURRENT_WRITER_KEY);
+ }
private static void setCurrentInstance(StateWriter stateWriter)
{
@@ -75,6 +80,20 @@ public final class StateWriter extends W
facesContext.getAttributes().put(CURRENT_WRITER_KEY, stateWriter);
}
}
+
+ private static void setCurrentInstance(StateWriter stateWriter, FacesContext facesContext)
+ {
+ //FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (stateWriter == null)
+ {
+ facesContext.getAttributes().remove(CURRENT_WRITER_KEY);
+ }
+ else
+ {
+ facesContext.getAttributes().put(CURRENT_WRITER_KEY, stateWriter);
+ }
+ }
public StateWriter(Writer initialOut, int initialSize)
{
@@ -85,9 +104,20 @@ public final class StateWriter extends W
this.initialSize = initialSize;
this.out = initialOut;
-
setCurrentInstance(this);
}
+
+ public StateWriter(Writer initialOut, int initialSize, FacesContext facesContext)
+ {
+ if (initialSize < 0)
+ {
+ throw new IllegalArgumentException("Initial Size cannot be less than 0");
+ }
+
+ this.initialSize = initialSize;
+ this.out = initialOut;
+ setCurrentInstance(this, facesContext);
+ }
/**
* Mark that state is about to be written. Contrary to what you'd expect, we cannot and should not assume that this
@@ -176,5 +206,11 @@ public final class StateWriter extends W
// remove from FacesContext attribute Map
setCurrentInstance(null);
}
+
+ public void release(FacesContext facesContext)
+ {
+ // remove from FacesContext attribute Map
+ setCurrentInstance(null, facesContext);
+ }
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java Tue May 22 10:57:55 2012
@@ -128,7 +128,7 @@ final class UIInstructionHandler extends
//c.setId(ComponentSupport.getViewRoot(ctx, parent).createUniqueId());
UniqueIdVendor uniqueIdVendor
- = FaceletCompositionContext.getCurrentInstance(ctx).getUniqueIdVendorFromStack();
+ = mctx.getUniqueIdVendorFromStack();
if (uniqueIdVendor == null)
{
uniqueIdVendor = ComponentSupport.getViewRoot(ctx, parent);
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java Tue May 22 10:57:55 2012
@@ -317,7 +317,8 @@ public class CompositeComponentResourceT
if (compositeFacetPanel == null)
{
compositeFacetPanel = (UIPanel)
- faceletContext.getFacesContext().getApplication().createComponent(UIPanel.COMPONENT_TYPE);
+ faceletContext.getFacesContext().getApplication().createComponent(
+ faceletContext.getFacesContext(), UIPanel.COMPONENT_TYPE, null);
compositeComponentBase.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, compositeFacetPanel);
// Set an id to the created facet component, to prevent id generation and make
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java Tue May 22 10:57:55 2012
@@ -369,7 +369,7 @@ public final class ComponentSupport
private static UIComponent createFacetUIPanel(FaceletContext ctx, UIComponent parent, String facetName)
{
FacesContext facesContext = ctx.getFacesContext();
- UIComponent panel = facesContext.getApplication().createComponent(UIPanel.COMPONENT_TYPE);
+ UIComponent panel = facesContext.getApplication().createComponent(facesContext, UIPanel.COMPONENT_TYPE, null);
// The panel created by this method is special. To be restored properly and do not
// create duplicate ids or any other unwanted conflicts, it requires an unique id.
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java Tue May 22 10:57:55 2012
@@ -436,14 +436,20 @@ public class ComponentTagHandlerDelegate
}
else
{
+ // According to the, spec call the second alternative with null rendererType gives
+ // the same result, but without the unnecesary call for FacesContext.getCurrentInstance().
+ // Saves 1 call per component without rendererType (f:viewParam, h:column, f:selectItem, ...)
+ // and it does not have any side effects (the spec javadoc mentions in a explicit way
+ // that rendererType can be null!).
+ /*
if (this._rendererType == null)
{
c = app.createComponent(this._componentType);
}
else
- {
+ {*/
c = app.createComponent(faces, this._componentType, this._rendererType);
- }
+ //}
}
return c;
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ViewMetadataHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ViewMetadataHandler.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ViewMetadataHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ViewMetadataHandler.java Tue May 22 10:57:55 2012
@@ -65,7 +65,8 @@ public final class ViewMetadataHandler e
UIComponent metadataFacet = parent.getFacet(UIViewRoot.METADATA_FACET_NAME);
if (metadataFacet == null)
{
- metadataFacet = ctx.getFacesContext().getApplication().createComponent(UIPanel.COMPONENT_TYPE);
+ metadataFacet = ctx.getFacesContext().getApplication().createComponent(
+ ctx.getFacesContext(), UIPanel.COMPONENT_TYPE, null);
metadataFacet.setId(UIViewRoot.METADATA_FACET_NAME);
metadataFacet.getAttributes().put(ComponentSupport.FACET_CREATED_UIPANEL_MARKER, true);
parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, metadataFacet);
Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java (original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java Tue May 22 10:57:55 2012
@@ -103,7 +103,7 @@ public class HtmlButtonRendererBase
if (formInfo != null)
{
hiddenLink = (String) facesContext.getExternalContext().getRequestParameterMap().get(
- HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo));
+ HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo, facesContext));
}
return paramMap.containsKey(clientId) || paramMap.containsKey(clientId + IMAGE_BUTTON_SUFFIX_X)
|| paramMap.containsKey(clientId + IMAGE_BUTTON_SUFFIX_Y)
@@ -622,7 +622,8 @@ public class HtmlButtonRendererBase
if (MyfacesConfig.getCurrentInstance(
facesContext.getExternalContext()).isRenderHiddenFieldsForLinkParams())
{
- String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(nestedFormInfo);
+ String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(
+ nestedFormInfo, facesContext);
addHiddenCommandParameter(facesContext, nestedFormInfo.getForm(), hiddenFieldName);
}
}
Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlLinkRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlLinkRendererBase.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlLinkRendererBase.java (original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlLinkRendererBase.java Tue May 22 10:57:55 2012
@@ -87,7 +87,7 @@ public abstract class HtmlLinkRendererBa
if (formInfo != null)
{
String reqValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(
- HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo));
+ HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo, facesContext));
if (reqValue != null && reqValue.equals(clientId)
|| HtmlRendererUtils.isPartialOrBehaviorSubmit(facesContext, clientId))
{
@@ -475,7 +475,8 @@ public abstract class HtmlLinkRendererBa
if (MyfacesConfig.getCurrentInstance(
facesContext.getExternalContext()).isRenderHiddenFieldsForLinkParams())
{
- String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo);
+ String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(
+ formInfo, facesContext);
addHiddenCommandParameter(facesContext, nestingForm, hiddenFieldName);
}
@@ -790,7 +791,8 @@ public abstract class HtmlLinkRendererBa
hrefBuf.append('&');
}
}
- String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo);
+ String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(
+ formInfo, facesContext);
hrefBuf.append(hiddenFieldName);
hrefBuf.append('=');
hrefBuf.append(clientId);
Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=1341400&r1=1341399&r2=1341400&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java Tue May 22 10:57:55 2012
@@ -1586,6 +1586,17 @@ public final class HtmlRendererUtils
return formInfo.getFormName() + UINamingContainer.getSeparatorChar(FacesContext
.getCurrentInstance()) + HIDDEN_COMMANDLINK_FIELD_NAME;
}
+
+ public static String getHiddenCommandLinkFieldName(
+ FormInfo formInfo, FacesContext facesContext)
+ {
+ if (RendererUtils.isAdfOrTrinidadForm(formInfo.getForm()))
+ {
+ return HIDDEN_COMMANDLINK_FIELD_NAME_TRINIDAD;
+ }
+ return formInfo.getFormName() + UINamingContainer.getSeparatorChar(facesContext)
+ + HIDDEN_COMMANDLINK_FIELD_NAME;
+ }
public static boolean isPartialOrBehaviorSubmit(FacesContext facesContext,
String clientId)
@@ -1614,11 +1625,6 @@ public final class HtmlRendererUtils
return partialOrBehaviorSubmit;
}
- /**
- * @param formInfo
- * @return
- * @deprecated Use getHiddenCommandLinkFieldNameMyfaces(FormInfo) instead
- */
public static String getHiddenCommandLinkFieldNameMyfacesOld(
FormInfo formInfo)
{
@@ -1729,18 +1735,15 @@ public final class HtmlRendererUtils
private static final String HTML_CONTENT_TYPE = "text/html";
private static final String TEXT_ANY_CONTENT_TYPE = "text/*";
private static final String ANY_CONTENT_TYPE = "*/*";
-
public static final String DEFAULT_CHAR_ENCODING = "ISO-8859-1";
private static final String XHTML_CONTENT_TYPE = "application/xhtml+xml";
private static final String APPLICATION_XML_CONTENT_TYPE = "application/xml";
private static final String TEXT_XML_CONTENT_TYPE = "text/xml";
-
// The order is important in this case.
private static final String[] SUPPORTED_CONTENT_TYPES = {
HTML_CONTENT_TYPE, //Prefer this over any other, because IE does not support XHTML content type
XHTML_CONTENT_TYPE, APPLICATION_XML_CONTENT_TYPE,
TEXT_XML_CONTENT_TYPE, TEXT_ANY_CONTENT_TYPE, ANY_CONTENT_TYPE };
-
/**
* @deprecated use ContentTypeUtils instead
*/
@@ -2942,7 +2945,6 @@ public final class HtmlRendererUtils
/**
* Returns the value of the hideNoSelectionOption attribute of the given UIComponent
- *
* @param component
* @return
*/
@@ -2959,7 +2961,6 @@ public final class HtmlRendererUtils
/**
* Renders all FacesMessages which have not been rendered yet with
* the help of a HtmlMessages component.
- *
* @param facesContext
*/
public static void renderUnhandledFacesMessages(FacesContext facesContext)