dev@javaserverfaces.java.net

Seeking Review: removal of AfterAddToParentEvent

From: Ed Burns <Ed.Burns_at_Sun.COM>
Date: Fri, 06 Feb 2009 12:15:36 -0800

AfterAddToViewEvent takes its place.

Issue: remove AfterAddToParentEvent. Not needed when we have
AfterAddToViewEvent.


SECTION: Modified Files
----------------------------
M jsf-api/test/javax/faces/component/UIComponentBaseTestCase.java

- afterAddToView needs its parents to be in the view

M jsf-api/doc/standard-html-renderkit-base.xml
M jsf-api/doc/standard-html-renderkit.xml
M jsf-api/src/javax/faces/event/ListenersFor.java
M jsf-api/src/javax/faces/event/ListenerFor.java
M jsf-api/src/javax/faces/component/UIComponent.java
M jsf-ri/test/com/sun/faces/application/TestApplicationImpl.java
M jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/AjaxHandler.java
M jsf-ri/src/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java
M jsf-ri/systest/src/com/sun/faces/systest/tags/EventTestCase.java
M jsf-ri/systest/web/eventTag.xhtml

- s/AfterAddToParent/AfterAddToView/g

M jsf-api/src/javax/faces/component/UIComponentBase.java

- In doPostAddProcessing(), remove publish of AfterAddToParentEvent.

M jsf-ri/src/com/sun/faces/lifecycle/RestoreViewPhase.java

- send the AfterAddToViewEvent instead of the AfterAddToParentEvent for
  the viewRoot.

M jsf-ri/src/com/sun/faces/application/NamedEventManager.java

- remove AfterAddToParent support

D jsf-api/src/javax/faces/event/AfterAddToParentEvent.java

- remove the class.


SECTION: Diffs
----------------------------
Index: jsf-api/test/javax/faces/component/UIComponentBaseTestCase.java
===================================================================
--- jsf-api/test/javax/faces/component/UIComponentBaseTestCase.java (revision 6428)
+++ jsf-api/test/javax/faces/component/UIComponentBaseTestCase.java (working copy)
 -58,7 +58,7 @@
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.SystemEventListener;
 import javax.faces.event.SystemEvent;
-import javax.faces.event.AfterAddToParentEvent;
+import javax.faces.event.AfterAddToViewEvent;
 import javax.faces.event.BeforeRenderEvent;
 import javax.faces.event.ComponentSystemEventListener;
 import javax.faces.event.ComponentSystemEvent;
 -380,13 +380,13 @@
     public void testStateHolder2() throws Exception {
 
         UIComponent c = new UIComponentListener();
- c.subscribeToEvent(AfterAddToParentEvent.class, (ComponentSystemEventListener) c);
+ c.subscribeToEvent(AfterAddToViewEvent.class, (ComponentSystemEventListener) c);
         Object state = c.saveState(facesContext);
         c = new UIComponentListener();
         c.pushComponentToEL(facesContext, c);
         c.restoreState(facesContext, state);
         c.popComponentFromEL(facesContext);
- assertTrue(c.getListenersForEventClass(AfterAddToParentEvent.class).size() == 1);
+ assertTrue(c.getListenersForEventClass(AfterAddToViewEvent.class).size() == 1);
         
     }
 
 -899,8 +899,8 @@
 
     protected void checkComponentListeners(UIComponent control, UIComponent toValidate) {
 
- List<SystemEventListener> lc = control.getListenersForEventClass(AfterAddToParentEvent.class);
- List<SystemEventListener> tvl = toValidate.getListenersForEventClass(AfterAddToParentEvent.class);
+ List<SystemEventListener> lc = control.getListenersForEventClass(AfterAddToViewEvent.class);
+ List<SystemEventListener> tvl = toValidate.getListenersForEventClass(AfterAddToViewEvent.class);
         List<SystemEventListener> lc2 = control.getListenersForEventClass(ViewMapCreatedEvent.class);
         List<SystemEventListener> tvl2 = toValidate.getListenersForEventClass(ViewMapCreatedEvent.class);
 
 -930,9 +930,9 @@
                                   application.createValueBinding("baz.value"));
         component.setValueBinding("bop",
                                   application.createValueBinding("bop.value"));
- component.subscribeToEvent(AfterAddToParentEvent.class,
+ component.subscribeToEvent(AfterAddToViewEvent.class,
                                    new ComponentListener());
- component.subscribeToEvent(AfterAddToParentEvent.class,
+ component.subscribeToEvent(AfterAddToViewEvent.class,
                                    new ComponentListener());
         component.subscribeToEvent(ViewMapCreatedEvent.class,
                                    new ComponentListener());
 -1395,11 +1395,14 @@
     public void testChildrenListAfterAddPublish() {
 
         Listener listener = new Listener();
- application.subscribeToEvent(AfterAddToParentEvent.class, listener);
+ application.subscribeToEvent(AfterAddToViewEvent.class, listener);
 
         UIComponent c1 = createComponent();
+ c1.setInView(true);
         UIComponent c2 = createComponent();
+ c2.setInView(true);
         UIComponent c3 = createComponent();
+ c3.setInView(true);
 
         c1.getChildren().add(c2);
         SystemEvent e = listener.getEvent();
 -1422,7 +1425,7 @@
         assertTrue(e.getSource() == c3);
         assertTrue(((UIComponent) e.getSource()).getParent() == c1);
 
- application.unsubscribeFromEvent(AfterAddToParentEvent.class, listener);
+ application.unsubscribeFromEvent(AfterAddToViewEvent.class, listener);
 
     }
 
Index: jsf-api/doc/standard-html-renderkit-base.xml
===================================================================
--- jsf-api/doc/standard-html-renderkit-base.xml (revision 6428)
+++ jsf-api/doc/standard-html-renderkit-base.xml (working copy)
 -2751,7 +2751,7 @@
 <p>The implementation of this renderer must have a <a target="_"
 href="../../javadocs/javax/faces/event/ListenerFor.html"><code>@ListenerFor</code></a>
 annotation attached to it, at the class level, declaring <a target="_"
-href="../../javadocs/javax/faces/event/AfterAddToParentEvent.html"><code>AfterAddToParentEvent.class</code></a>
+href="../../javadocs/javax/faces/event/AfterAddToViewEvent.html"><code>AfterAddToViewEvent.class</code></a>
 as the value of the <code>systemEventClass</code> attribute. The presence of
 this annotation on a renderer implies the renderer implements <a
 target="_"
 -2931,7 +2931,7 @@
 <p>The implementation of this renderer must have a <a target="_"
 href="../../javadocs/javax/faces/event/ListenerFor.html"><code>@ListenerFor</code></a>
 annotation attached to it, at the class level, declaring <a target="_"
-href="../../javadocs/javax/faces/event/AfterAddToParentEvent.html"><code>AfterAddToParentEvent.class</code></a>
+href="../../javadocs/javax/faces/event/AfterAddToViewEvent.html"><code>AfterAddToViewEvent.class</code></a>
 as the value of the <code>systemEventClass</code> attribute. The presence of
 this annotation on a renderer implies the renderer implements <a target="_"
 href="../../javadocs/javax/faces/event/ComponentSystemEventListener.html"><code>ComponentSystemEventListener</code></a>,
Index: jsf-api/doc/standard-html-renderkit.xml
===================================================================
--- jsf-api/doc/standard-html-renderkit.xml (revision 6428)
+++ jsf-api/doc/standard-html-renderkit.xml (working copy)
 -26705,7 +26705,7 @@
 <p>The implementation of this renderer must have a <a target="_"
 href="../../javadocs/javax/faces/event/ListenerFor.html"><code>@ListenerFor</code></a>
 annotation attached to it, at the class level, declaring <a target="_"
-href="../../javadocs/javax/faces/event/AfterAddToParentEvent.html"><code>AfterAddToParentEvent.class</code></a>
+href="../../javadocs/javax/faces/event/AfterAddToViewEvent.html"><code>AfterAddToViewEvent.class</code></a>
 as the value of the <code>systemEventClass</code> attribute. The presence of
 this annotation on a renderer implies the renderer implements <a
 target="_"
 -26918,7 +26918,7 @@
 <p>The implementation of this renderer must have a <a target="_"
 href="../../javadocs/javax/faces/event/ListenerFor.html"><code>@ListenerFor</code></a>
 annotation attached to it, at the class level, declaring <a target="_"
-href="../../javadocs/javax/faces/event/AfterAddToParentEvent.html"><code>AfterAddToParentEvent.class</code></a>
+href="../../javadocs/javax/faces/event/AfterAddToViewEvent.html"><code>AfterAddToViewEvent.class</code></a>
 as the value of the <code>systemEventClass</code> attribute. The presence of
 this annotation on a renderer implies the renderer implements <a target="_"
 href="../../javadocs/javax/faces/event/ComponentSystemEventListener.html"><code>ComponentSystemEventListener</code></a>,
Index: jsf-api/src/javax/faces/event/ListenersFor.java
===================================================================
--- jsf-api/src/javax/faces/event/ListenersFor.java (revision 6428)
+++ jsf-api/src/javax/faces/event/ListenersFor.java (working copy)
 -51,7 +51,7 @@
  * <pre><code>
 
     @ListenersFor({
- @ListenerFor(systemEventClass=AfterAddToParentEvent.class),
+ @ListenerFor(systemEventClass=AfterAddToViewEvent.class),
         @ListenerFor(systemEventClass=BeforeRenderEvent.class,
                      sourceClass=CustomOutput.class)
     })
Index: jsf-api/src/javax/faces/event/AfterAddToParentEvent.java
===================================================================
--- jsf-api/src/javax/faces/event/AfterAddToParentEvent.java (revision 6428)
+++ jsf-api/src/javax/faces/event/AfterAddToParentEvent.java (working copy)
 -1,80 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package javax.faces.event;
-
-import javax.faces.component.UIComponent;
-
-/**
- *
- * <p class="changed_added_2_0">When an instance of this event is passed
- * to {_at_link SystemEventListener#processEvent} or {_at_link
- * ComponentSystemEventListener#processEvent}, the listener
- * implementation may assume that the <code>source</code> of this event
- * instance is the {_at_link UIComponent} instance that was just added to
- * its parent. </p>
- *
- * <div class="changed_added_2_0">
- *
- * <p>The implementation must guarantee that {_at_link
- * javax.faces.application.Application#publishEvent} is called,
- * immediately after any <code>UIComponent</code> instance is added to
- * the view hierarchy <strong>except</strong> in the case where {_at_link
- * javax.faces.render.ResponseStateManager#isPostback} returns
- * <code>true</code> <strong>at the same time as</strong> {_at_link
- * javax.faces.context.FacesContext#getCurrentPhaseId} returns {_at_link
- * javax.faces.event.PhaseId#RESTORE_VIEW}. When both of those
- * conditions are met, {_at_link
- * javax.faces.application.Application#publishEvent} must not be called.</p>
- *
- * </div>
- *
- * @since 2.0
- */
-public class AfterAddToParentEvent extends ComponentSystemEvent {
-
-
- private static final long serialVersionUID = -5706460518363094948L;
-
-
- // ------------------------------------------------------------ Constructors
-
-
- /**
- * <p class="changed_added_2_0">Instantiate a new
- * <code>AfterAddToParentEvent</code> that indicates the argument
- * <code>component</code> was just added to the view.</p>
-
- * @param component the <code>UIComponent</code> that has just been
- * added to the view.
- *
- * @throws IllegalArgumentException if <code>component</code> is
- * <code>null</code>
- */
- public AfterAddToParentEvent(UIComponent component) {
-
- super(component);
-
- }
-
-
- // --------------------------------------- Methods from ComponentSystemEvent
-
-
- /**
- * <p class="changed_added_2_0">Returns <code>true</code> if and
- * only if the argument <code>listener</code> is an instance of
- * {_at_link SystemEventListener}.</p>
- * @param listener
- */
- @Override
- public boolean isAppropriateListener(FacesListener listener) {
-
- return (listener instanceof SystemEventListener);
-
- }
-
-
-}
Index: jsf-api/src/javax/faces/event/ListenerFor.java
===================================================================
--- jsf-api/src/javax/faces/event/ListenerFor.java (revision 6428)
+++ jsf-api/src/javax/faces/event/ListenerFor.java (working copy)
 -107,10 +107,10 @@
  * <code>javax.faces.resource.Stylesheet</code> must have the following
  * annotation declaration:</p>
 
- * <pre><code>@ListenerFor(systemEventClass=AfterAddToParentEvent.class)</code></pre>
+ * <pre><code>@ListenerFor(systemEventClass=AfterAddToViewEvent.class)</code></pre>
 
  * <p>This will cause the renderer to be added as a listener for the
- * {_at_link AfterAddToParentEvent} no all components that list it as their
+ * {_at_link AfterAddToViewEvent} no all components that list it as their
  * renderer.</p>
 
  * </div>
Index: jsf-api/src/javax/faces/component/UIComponent.java
===================================================================
--- jsf-api/src/javax/faces/component/UIComponent.java (revision 6428)
+++ jsf-api/src/javax/faces/component/UIComponent.java (working copy)
 -582,7 +582,7 @@
      * RELEASE_PENDING (edburns,rogerk) review docus
      * <p class="changed_modified_2_0">Set the parent <code>UIComponent</code> of this
      * <code>UIComponent</code>. This method, when called will cause
- * an {_at_link javax.faces.event.AfterAddToParentEvent} to be published and
+ * an {_at_link javax.faces.event.AfterAddToViewEvent} to be published and
      * if <code>parent.isInView()</code> returns <code>true</code> an
      * {_at_link javax.faces.event.AfterAddToViewEvent} will be published as well.
      * <strong>This method must never be called by developers; a
 -965,7 +965,7 @@
 
      * <p>{_at_link javax.faces.application.Application#publishEvent}
      * must be called, passing {_at_link
- * javax.faces.event.AfterAddToParentEvent}<code>.class</code>
+ * javax.faces.event.AfterAddToViewEvent}<code>.class</code>
      * as the first argument and the newly added component as the
      * second argument.</p>
 
Index: jsf-api/src/javax/faces/component/UIComponentBase.java
===================================================================
--- jsf-api/src/javax/faces/component/UIComponentBase.java (revision 6428)
+++ jsf-api/src/javax/faces/component/UIComponentBase.java (working copy)
 -1577,8 +1577,6 @@
     private void doPostAddProcessing(FacesContext context, UIComponent added) {
 
         if (!isPostbackAndRestoreView(context)) {
- context.getApplication().publishEvent(AfterAddToParentEvent.class,
- added);
             if (parent.isInView()) {
                 publishAfterViewEvents(context.getApplication(), added);
             }
Index: jsf-ri/test/com/sun/faces/application/TestApplicationImpl.java
===================================================================
--- jsf-ri/test/com/sun/faces/application/TestApplicationImpl.java (revision 6428)
+++ jsf-ri/test/com/sun/faces/application/TestApplicationImpl.java (working copy)
 -76,7 +76,7 @@
 import javax.faces.event.ActionEvent;
 import javax.faces.event.ActionListener;
 import javax.faces.event.ListenerFor;
-import javax.faces.event.AfterAddToParentEvent;
+import javax.faces.event.AfterAddToViewEvent;
 import javax.faces.event.ComponentSystemEventListener;
 import javax.faces.event.ComponentSystemEvent;
 import javax.faces.event.AbortProcessingException;
 -716,8 +716,8 @@
         UIViewRoot root = getFacesContext().getViewRoot();
         root.getChildren().add(c);
         root.getChildren().add(c2);
- assertTrue(c.getEvent() instanceof AfterAddToParentEvent);
- assertTrue(c2.getEvent() instanceof AfterAddToParentEvent);
+ assertTrue(c.getEvent() instanceof AfterAddToViewEvent);
+ assertTrue(c2.getEvent() instanceof AfterAddToViewEvent);
         List<UIComponent> headComponents = root.getComponentResources(getFacesContext(), "head");
         System.out.println(headComponents.toString());
         assertTrue(headComponents.size() == 1);
 -732,7 +732,7 @@
         application.addComponent("CustomInput2", CustomOutput2.class.getName());
         CustomOutput2 c3 = (CustomOutput2) application.createComponent("CustomInput2");
         root.getChildren().add(c3);
- assertTrue(c3.getEvent() instanceof AfterAddToParentEvent);
+ assertTrue(c3.getEvent() instanceof AfterAddToViewEvent);
         c3.reset();
         c3.encodeAll(getFacesContext());
         assertTrue(c3.getEvent() instanceof BeforeRenderEvent);
 -794,7 +794,7 @@
         }
     }
 
- @ListenerFor(systemEventClass=AfterAddToParentEvent.class,
+ @ListenerFor(systemEventClass=AfterAddToViewEvent.class,
                  sourceClass= CustomOutput.class)
     @ResourceDependencies({
         @ResourceDependency(name="#{'test.js'}",library="test",target="#{'body'}"),
 -828,7 +828,7 @@
     }
 
     @ListenersFor({
- @ListenerFor(systemEventClass = AfterAddToParentEvent.class,
+ @ListenerFor(systemEventClass = AfterAddToViewEvent.class,
                      sourceClass = CustomOutput.class),
         @ListenerFor(systemEventClass = BeforeRenderEvent.class,
                      sourceClass = CustomOutput.class)
Index: jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/AjaxHandler.java
===================================================================
--- jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/AjaxHandler.java (revision 6428)
+++ jsf-ri/src/com/sun/faces/facelets/tag/jsf/core/AjaxHandler.java (working copy)
 -105,7 +105,7 @@
  * If this tag is nested within a component other than an
  * {_at_link javax.faces.component.ActionSource} or
  * {_at_link javax.faces.component.EditableValueHolder} type,
- * make this tag's parent component subscribe to {_at_link javax.faces.event.AfterAddToParentEvent}
+ * make this tag's parent component subscribe to {_at_link javax.faces.event.AfterAddToViewEvent}
  * events. Retrieve an {_at_link javax.faces.component.AjaxBehaviors} instance from
  * the current {_at_link javax.faces.context.FacesContext} attributes <code>Map</code>
  * using the key {_at_link javax.faces.component.AjaxBehaviors#AJAX_BEHAVIORS}. If an instance does not exist,
Index: jsf-ri/src/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java
===================================================================
--- jsf-ri/src/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java (revision 6428)
+++ jsf-ri/src/com/sun/faces/renderkit/html_basic/ScriptStyleBaseRenderer.java (working copy)
 -48,7 +48,7 @@
 import javax.faces.context.ResponseWriter;
 import javax.faces.render.Renderer;
 import javax.faces.event.AbortProcessingException;
-import javax.faces.event.AfterAddToParentEvent;
+import javax.faces.event.AfterAddToViewEvent;
 import javax.faces.event.ComponentSystemEvent;
 import javax.faces.event.ComponentSystemEventListener;
 import javax.faces.event.ListenerFor;
 -57,7 +57,7 @@
  * <p>Base class for shared behavior between Script and Stylesheet renderers.
  * Maybe composition would be better, but inheritance is easier</p>
  */
-_at_ListenerFor(systemEventClass=AfterAddToParentEvent.class)
+_at_ListenerFor(systemEventClass=AfterAddToViewEvent.class)
 public abstract class ScriptStyleBaseRenderer extends Renderer implements ComponentSystemEventListener {
     
     
Index: jsf-ri/src/com/sun/faces/lifecycle/RestoreViewPhase.java
===================================================================
--- jsf-ri/src/com/sun/faces/lifecycle/RestoreViewPhase.java (revision 6428)
+++ jsf-ri/src/com/sun/faces/lifecycle/RestoreViewPhase.java (working copy)
 -66,7 +66,7 @@
 import com.sun.faces.util.Util;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.event.AbortProcessingException;
-import javax.faces.event.AfterAddToParentEvent;
+import javax.faces.event.AfterAddToViewEvent;
 import javax.faces.event.AfterRestoreStateEvent;
 import javax.faces.event.ExceptionEvent;
 import javax.faces.event.ExceptionEventContext;
 -202,7 +202,7 @@
                   createView(facesContext, viewId);
             facesContext.setViewRoot(viewRoot);
             facesContext.renderResponse();
- facesContext.getApplication().publishEvent(AfterAddToParentEvent.class,
+ facesContext.getApplication().publishEvent(AfterAddToViewEvent.class,
                                                        viewRoot);
         }
         assert(null != viewRoot);
Index: jsf-ri/src/com/sun/faces/application/NamedEventManager.java
===================================================================
--- jsf-ri/src/com/sun/faces/application/NamedEventManager.java (revision 6428)
+++ jsf-ri/src/com/sun/faces/application/NamedEventManager.java (working copy)
 -8,7 +8,6 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import javax.faces.event.AfterAddToParentEvent;
 import javax.faces.event.AfterAddToViewEvent;
 import javax.faces.event.AfterValidateEvent;
 import javax.faces.event.BeforeRenderEvent;
 -27,12 +26,10 @@
 
     public NamedEventManager() {
         namedEvents.put("javax.faces.event.beforeRender", BeforeRenderEvent.class);
- namedEvents.put("javax.faces.event.afterAddToParent", AfterAddToParentEvent.class);
         namedEvents.put("javax.faces.event.afterAddToView", AfterAddToViewEvent.class);
         namedEvents.put("javax.faces.event.BeforeValidate", BeforeValidateEvent.class);
         namedEvents.put("javax.faces.event.AfterValidate", AfterValidateEvent.class);
         namedEvents.put("beforeRender", BeforeRenderEvent.class);
- namedEvents.put("afterAddToParent", AfterAddToParentEvent.class);
         namedEvents.put("afterAddToView", AfterAddToViewEvent.class);
         namedEvents.put("beforeValidate", BeforeValidateEvent.class);
         namedEvents.put("afterValidate", AfterValidateEvent.class);
Index: jsf-ri/systest/src/com/sun/faces/systest/tags/EventTestCase.java
===================================================================
--- jsf-ri/systest/src/com/sun/faces/systest/tags/EventTestCase.java (revision 6428)
+++ jsf-ri/systest/src/com/sun/faces/systest/tags/EventTestCase.java (working copy)
 -142,11 +142,11 @@
 
         // Short Name
         s = outputs.get(2);
- assertTrue(("The 'javax.faces.event.AfterAddToParentEvent' event fired!").equals(s.asText()));
+ assertTrue(("The 'javax.faces.event.AfterAddToViewEvent' event fired!").equals(s.asText()));
 
         // Long name
         s = outputs.get(3);
- assertTrue(("The 'javax.faces.event.AfterAddToParentEvent' event fired!").equals(s.asText()));
+ assertTrue(("The 'javax.faces.event.AfterAddToViewEvent' event fired!").equals(s.asText()));
 
     }
-}
\ No newline at end of file
+}
Index: jsf-ri/systest/web/eventTag.xhtml
===================================================================
--- jsf-ri/systest/web/eventTag.xhtml (revision 6428)
+++ jsf-ri/systest/web/eventTag.xhtml (working copy)
 -54,12 +54,12 @@
             <f:event type="javax.faces.event.beforeRender" listener="#{eventTagBean.beforeEncode}" />
         </h:outputText>
         <br />
- <h:outputText id="afterAddToParentTest1" >
- <f:event type="afterAddToParent" listener="#{eventTagBean.beforeEncode}" />
+ <h:outputText id="afterAddToViewTest1" >
+ <f:event type="afterAddToView" listener="#{eventTagBean.beforeEncode}" />
         </h:outputText>
         <br />
- <h:outputText id="afterAddToParentTest2" >
- <f:event type="javax.faces.event.afterAddToParent" listener="#{eventTagBean.beforeEncode}" />
+ <h:outputText id="afterAddToViewTest2" >
+ <f:event type="javax.faces.event.afterAddToView" listener="#{eventTagBean.beforeEncode}" />
         </h:outputText>
         <h:commandButton id="click" value="Click" />
     </h:form>

-- 
| ed.burns_at_sun.com  | office: 408 884 9519 OR x31640
| homepage:         | http://ridingthecrest.com/