https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=868
Make UIComponent.CURRENT_*COMPONENT not turned on by default
https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=868
SECTION: Modified Files
----------------------------
M jsf-api/src/test/java/javax/faces/component/UIComponentBaseTestCase.java
- test that the backwards compat works and does not work, depending on
the init param.
M jsf-api/src/main/java/javax/faces/component/UIComponent.java
- disable the CURRENT_*COMPONENT by default.
M jsf-api/build.xml
- add passthru convenience target
SECTION: Diffs
----------------------------
Index: jsf-api/src/test/java/javax/faces/component/UIComponentBaseTestCase.java
===================================================================
--- jsf-api/src/test/java/javax/faces/component/UIComponentBaseTestCase.java (revision 8545)
+++ jsf-api/src/test/java/javax/faces/component/UIComponentBaseTestCase.java (working copy)
@@ -36,6 +36,7 @@
package javax.faces.component;
+import com.sun.faces.mock.MockExternalContext;
import com.sun.faces.mock.MockValueBinding;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -132,9 +133,10 @@
}
- public void testComponentToFromEL() {
+ public void testComponentToFromELBackwardCompatible() {
final String key = UIComponent.CURRENT_COMPONENT;
+ ((MockExternalContext)this.facesContext.getExternalContext()).addInitParameter(UIComponent.HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, "true");
TestComponent c = new TestComponent();
facesContext.getAttributes().clear();
assertNull(facesContext.getAttributes().get(key));
@@ -145,7 +147,19 @@
}
+ public void testComponentToFromEL() {
+ final String key = UIComponent.CURRENT_COMPONENT;
+ TestComponent c = new TestComponent();
+ facesContext.getAttributes().clear();
+ assertNull(facesContext.getAttributes().get(key));
+ c.pushComponentToEL(facesContext, null);
+ assertFalse(facesContext.getAttributes().get(key) == c);
+ c.popComponentFromEL(facesContext);
+ assertNull(facesContext.getAttributes().get(key));
+
+ }
+
public void testComponentToFromEL2() throws Exception {
final String key = UIComponent.CURRENT_COMPONENT;
Index: jsf-api/src/main/java/javax/faces/component/UIComponent.java
===================================================================
--- jsf-api/src/main/java/javax/faces/component/UIComponent.java (revision 8545)
+++ jsf-api/src/main/java/javax/faces/component/UIComponent.java (working copy)
@@ -81,9 +81,9 @@
/**
* <p><strong class="changed_modified_2_0
- * changed_modified_2_0_rev_a">UIComponent</strong> is the base class
- * for all user interface components in JavaServer Faces. The set of
- * {_at_link UIComponent} instances associated with a particular request
+ * changed_modified_2_0_rev_a changed_modified_2_1">UIComponent</strong> is
+ * the base class for all user interface components in JavaServer Faces.
+ * The set of {_at_link UIComponent} instances associated with a particular request
* and response are organized into a component tree under a {_at_link
* UIViewRoot} that represents the entire content of the request or
* response.</p>
@@ -110,6 +110,21 @@
private static Logger LOGGER = Logger.getLogger("javax.faces.component",
"javax.faces.LogStrings");
+
+ /**
+ * <p class="changed_added_2_1">The <code>ServletContext</code> init
+ * parameter consulted by
+ * the <code>UIComponent</code> to tell whether or not the
+ * {_at_link #CURRENT_COMPONENT} and {_at_link #CURRENT_COMPOSITE_COMPONENT}
+ * attribute keys should be honored as specified.</p>
+ *
+ * <p>If this parameter is not specified, or is set to false, the contract
+ * specified by the {_at_link #CURRENT_COMPONENT} and
+ * {_at_link #CURRENT_COMPOSITE_COMPONENT} method is not honored. If this
+ * parameter is set to true, the contract is honored.</p>
+ */
+ public static final String HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME =
+ "javax.faces.HONOR_CURRENT_COMPONENT_ATTRIBUTES";
/**
* <p class="changed_added_2_0">The key to which the
@@ -1774,7 +1789,12 @@
component._isPushedAsCurrentRefCount++;
// we only do this because of the spec
- contextAttributes.put(UIComponent.CURRENT_COMPONENT, component);
+ boolean setCurrentComponent = false;
+ String val = context.getExternalContext().getInitParameter(UIComponent.HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME);
+ setCurrentComponent = Boolean.valueOf(val);
+ if (setCurrentComponent) {
+ contextAttributes.put(UIComponent.CURRENT_COMPONENT, component);
+ }
// if the pushed component is a composite component, we need to update that
// stack as well
@@ -1784,7 +1804,9 @@
contextAttributes).push(component);
// we only do this because of the spec
- contextAttributes.put(UIComponent.CURRENT_COMPOSITE_COMPONENT, component);
+ if (setCurrentComponent) {
+ contextAttributes.put(UIComponent.CURRENT_COMPOSITE_COMPONENT, component);
+ }
}
}
@@ -1849,9 +1871,16 @@
// pop ourselves off of the stack
componentELStack.pop();
_isPushedAsCurrentRefCount--;
-
+
+ boolean setCurrentComponent = false;
+ String val = context.getExternalContext().getInitParameter(UIComponent.HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME);
+ setCurrentComponent = Boolean.valueOf(val);
+
+
// update the current component with the new top of stack. We only do this because of the spec
- contextAttributes.put(UIComponent.CURRENT_COMPONENT, componentELStack.peek());
+ if (setCurrentComponent) {
+ contextAttributes.put(UIComponent.CURRENT_COMPONENT, componentELStack.peek());
+ }
// if we're a composite component, we also have to pop ourselves off of the
// composite stack
@@ -1862,11 +1891,12 @@
compositeELStack.pop();
// update the current composite component with the new top of stack.
- // We only do this because of the spec
- contextAttributes.put(UIComponent.CURRENT_COMPOSITE_COMPONENT, compositeELStack.peek());
+ // We only do this because of the spec
+ if (setCurrentComponent) {
+ contextAttributes.put(UIComponent.CURRENT_COMPOSITE_COMPONENT, compositeELStack.peek());
+ }
}
}
-
// It is safe to cache this because components never go from being
// composite to non-composite.
private transient Boolean isCompositeComponent = null;
@@ -1957,7 +1987,11 @@
* @since 2.0
*/
public static UIComponent getCurrentComponent(FacesContext context) {
- return (UIComponent)context.getAttributes().get(UIComponent.CURRENT_COMPONENT);
+ Map<Object, Object> contextAttributes = context.getAttributes();
+ ComponentStack componentELStack = _getComponentELStack(_CURRENT_COMPONENT_STACK_KEY,
+ contextAttributes);
+
+ return componentELStack.peek();
}
@@ -1975,7 +2009,11 @@
* @since 2.0
*/
public static UIComponent getCurrentCompositeComponent(FacesContext context) {
- return (UIComponent)context.getAttributes().get(UIComponent.CURRENT_COMPOSITE_COMPONENT);
+ // return (UIComponent)context.getAttributes().get(UIComponent.CURRENT_COMPOSITE_COMPONENT);
+ Map<Object, Object> contextAttributes = context.getAttributes();
+ ComponentStack compositeELStack = _getComponentELStack(_CURRENT_COMPOSITE_COMPONENT_STACK_KEY,
+ contextAttributes);
+ return compositeELStack.peek();
}
// -------------------------------------------------- Event Listener Methods
Index: jsf-api/build.xml
===================================================================
--- jsf-api/build.xml (revision 8545)
+++ jsf-api/build.xml (working copy)
@@ -874,4 +874,28 @@
<mvn.deploy.release groupId="javax.faces" version="${spec.version}" type="api"/>
</target>
+ <target name="passthru">
+ <echo message="Running javax.faces.component tests ..."/>
+ <delete file="${api.test.results.dir}/api-test.log"/>
+ <delete file="${api.test.results.dir}/test-logging.properties"/>
+ <echo file="${api.test.results.dir}/test-logging.properties">
+handlers=java.util.logging.FileHandler
+java.util.logging.FileHandler.append=true
+java.util.logging.FileHandler.encoding=UTF-8
+java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
+java.util.logging.FileHandler.pattern=${api.test.results.dir}/api-test.log
+javax.faces.level=ALL
+ </echo>
+ <jsf.junit test-results-dir="${api.test.results.dir}"
+ classpath-refid="test.classpath"
+ assert.classes="${assertion.classes}"
+ logging.config.file="${api.test.results.dir}/test-logging.properties">
+ <tests>
+ <fileset dir="${build.test.dir}"
+ includes="javax/faces/component/UIComponentBaseTestCase.class"/>
+ </tests>
+ </jsf.junit>
+ </target>
+
+
</project>
--
| edburns_at_oracle.com | office: +1 407 458 0017
| homepage: | http://ridingthecrest.com/
| 06 work days until JSF 2.1 Milestone 2