Author: craigmcc
Date: Sun Jul 16 20:17:18 2006
New Revision: 422609

URL: http://svn.apache.org/viewvc?rev=422609&view=rev
Log:
[SHALE-220] Resolve problems with the init() and destroy() methods being
called twice on a ViewController.

There were actually two related problems:

* The init() and destroy() methods were indeed being called twice.
  This was due to a change in the implemented support for these calls
  (the logic was migrated from ViewViewHandler to LifecycleListener),
  without accounting for the fact that the view controller instance was
  also being added as a reqeust scope attribute under the VIEW_RENDERED
  constant as well (which triggered the init/destroy behavior again).
  Fixed by storing the name of the corresponding managed bean, rather
  than the managed bean itself.

* The postBack property was not correctly initialized before the
  init() method was called, although it was set correctly before
  the preprocess() method was called (if it was, indeed, a post back).
  Fixed by initializing the postBack property in the constructor of
  AbstractViewController, and ensuring that the relevant request scope
  attribute was initialized before the managed bean was created.

While messing around with this functionality, I also took the
opportunity to isolate manifest constants that are internal to the
implementation out of org.apache.shale.view.Constants and into a private
package, so as to not confuse developers about what an application can
rely on.

Also, added a system integration test to the Use Cases example
application, to ensure the proper calling sequence of view controller
lifecycle events.


Added:
    
shale/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/view/TestViewController.java
    shale/trunk/shale-apps/shale-usecases/src/main/webapp/view/
    shale/trunk/shale-apps/shale-usecases/src/main/webapp/view/test.jsp
    
shale/trunk/shale-apps/shale-usecases/src/test/java/org/apache/shale/usecases/systest/ViewControllerTestCase.java
    
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/FacesConstants.java
Modified:
    
shale/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/faces-config.xml
    
shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
    shale/trunk/shale-core/src/main/java/org/apache/shale/component/Subview.java
    
shale/trunk/shale-core/src/main/java/org/apache/shale/view/AbstractViewController.java
    shale/trunk/shale-core/src/main/java/org/apache/shale/view/Constants.java
    
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java
    
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/LifecycleListener.java
    
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewPhaseListener.java
    
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewViewHandler.java

Added: 
shale/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/view/TestViewController.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/view/TestViewController.java?rev=422609&view=auto
==============================================================================
--- 
shale/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/view/TestViewController.java
 (added)
+++ 
shale/trunk/shale-apps/shale-usecases/src/main/java/org/apache/shale/usecases/view/TestViewController.java
 Sun Jul 16 20:17:18 2006
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.usecases.view;
+
+import java.util.Map;
+import org.apache.shale.view.AbstractViewController;
+
+/**
+ * <p>Test implementation of <code>Viewcontroller</code> for use by
+ * <code>ViewControllerTestCase</code>.  Event history is accumulated
+ * under a request scope attribute named by symbolic constant
+ * <code>ATTRIBUTES</code>.</p>
+ */
+public class TestViewController extends AbstractViewController {
+    
+    /** Creates a new instance of TestViewController */
+    public TestViewController() {
+    }
+    
+    // The request scope attribute under which we accumulate events
+    public static final String ATTRIBUTE =
+            "org.apache.shale.usecases.systest.TestViewController.EVENTS";
+
+
+    // ------------------------------------------------------- Public 
Properties
+
+
+    /**
+     * <p>Return the accumuated history string.</p>
+     */
+    public String getText() {
+        String history = (String) 
getExternalContext().getRequestMap().get(ATTRIBUTE);
+        if (history == null) {
+            history = "";
+        }
+        return history;
+    }
+
+
+    // ---------------------------------------------------------- Event 
Handlers
+
+
+    /**
+     * <p>Do-nothing submit method.</p>
+     */
+    public String submit() {
+        event("submit");
+        return null;
+    }
+
+
+    // ------------------------------------------------------- Lifecycle 
Methods
+
+
+    public void init() {
+        event("init");
+    }
+
+
+    public void preprocess() {
+        event("preprocess");
+    }
+
+
+    public void prerender() {
+        event("prerender");
+    }
+
+
+    public void destroy() {
+        event("destroy");
+    }
+
+
+    // --------------------------------------------------------- Support 
Methods
+
+
+    private Map map = null;
+
+
+    /**
+     * <p>Record the specified event, a slash, the state of the postback flag,
+     * and another slash.</p>
+     */
+    private void event(String event) {
+        System.out.println("TestViewController.event(" + event + "," + 
isPostBack() + ")");
+        if ("init".equals(event) || "destroy".equals(event)) {
+            try {
+                throw new IllegalArgumentException("Trace source of event '" + 
event + "'");
+            } catch (IllegalArgumentException e) {
+                e.printStackTrace();
+            }
+        }
+        if (map == null) {
+            map = getExternalContext().getRequestMap();
+        }
+        String history = (String) map.get(ATTRIBUTE);
+        if (history == null) {
+            history = "";
+        }
+        map.put(ATTRIBUTE, history + event + "/" + isPostBack() + "/");
+    }
+
+
+
+}

Modified: 
shale/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/faces-config.xml
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/faces-config.xml?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/faces-config.xml 
(original)
+++ 
shale/trunk/shale-apps/shale-usecases/src/main/webapp/WEB-INF/faces-config.xml 
Sun Jul 16 20:17:18 2006
@@ -217,6 +217,20 @@
   </navigation-rule>
 
 
+  <!-- ====================== View Controller Test ========================= 
-->
+
+
+  <!-- ViewController Beans -->
+
+  <managed-bean>
+    <managed-bean-name>view$test</managed-bean-name>
+    <managed-bean-class>
+      org.apache.shale.usecases.view.TestViewController
+    </managed-bean-class>
+    <managed-bean-scope>request</managed-bean-scope>
+  </managed-bean>
+
+
   <!-- ======================= Logon and Profile Edit Dialog =============== 
-->
 
 

Added: shale/trunk/shale-apps/shale-usecases/src/main/webapp/view/test.jsp
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-apps/shale-usecases/src/main/webapp/view/test.jsp?rev=422609&view=auto
==============================================================================
--- shale/trunk/shale-apps/shale-usecases/src/main/webapp/view/test.jsp (added)
+++ shale/trunk/shale-apps/shale-usecases/src/main/webapp/view/test.jsp Sun Jul 
16 20:17:18 2006
@@ -0,0 +1,52 @@
+<[EMAIL PROTECTED] contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"; %>
+<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"; %>
+<%@ taglib prefix="s" uri="http://shale.apache.org/core"; %>
+
+<%--
+
+ Copyright 2004-2005 The Apache Software Foundation.
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+--%>
+
+<f:view>
+<html>
+<head>
+<title>
+  <h:outputText         value="View Controller Test"/>
+</title>
+</head>
+<body>
+
+  <h:form                  id="form">
+
+    <hr/>
+
+    <h:outputText          id="text"
+                        value="#{view$test.text}"/>
+
+    <hr/>
+
+    <h:commandButton       id="submit"
+                         value="Submit"
+                       action="#{view$test.submit}"/>
+
+    <hr/>
+
+  </h:form>
+
+</body>
+</html>
+</f:view>

Added: 
shale/trunk/shale-apps/shale-usecases/src/test/java/org/apache/shale/usecases/systest/ViewControllerTestCase.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-apps/shale-usecases/src/test/java/org/apache/shale/usecases/systest/ViewControllerTestCase.java?rev=422609&view=auto
==============================================================================
--- 
shale/trunk/shale-apps/shale-usecases/src/test/java/org/apache/shale/usecases/systest/ViewControllerTestCase.java
 (added)
+++ 
shale/trunk/shale-apps/shale-usecases/src/test/java/org/apache/shale/usecases/systest/ViewControllerTestCase.java
 Sun Jul 16 20:17:18 2006
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.usecases.systest;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.shale.test.cargo.CargoTestSetup;
+
+/**
+ * <p>Test case for view controller lifecycle callbacks testing.</p>
+ */
+public class ViewControllerTestCase extends AbstractTestCase {
+
+
+    // ------------------------------------------------------------ 
Constructors
+
+
+    // Construct a new instance of this test case.
+    public ViewControllerTestCase(String name) {
+        super(name);
+    }
+
+
+    // ---------------------------------------------------- Overall Test 
Methods
+
+
+    // Set up instance variables required by this test case.
+    public void setUp() throws Exception {
+
+        super.setUp();
+        page("/view/test.faces");
+
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return new CargoTestSetup(new TestSuite(ViewControllerTestCase.class));
+
+    }
+
+
+    // Tear down instance variables required by this test case.
+    public void tearDown() {
+
+        super.tearDown();
+
+    }
+
+
+    // ------------------------------------------------------------ Test 
Methods
+
+
+    /**
+     * <p>Validate pristine instance of the test page.</p>
+     */
+    public void testPristine() throws Exception {
+
+        HtmlForm form = null;
+        HtmlElement text = null;
+        HtmlSubmitInput submit = null;
+
+        // setUp() should have put us on the page
+        assertEquals("View Controller Test", title());
+        form = (HtmlForm) element("form");
+        assertNotNull(form);
+        text = element("form:text");
+        assertNotNull(text);
+        submit = (HtmlSubmitInput) element("form:submit");
+        assertNotNull(submit);
+
+        // Check the expected contents of the "text" element on
+        // an initial request for this page.  Note that we cannot
+        // check for the destroy event, because it has not yet occurred
+        // when the value binding expression in our test page is evaluated
+        assertEquals("init/false/prerender/false/", text.asText());
+
+    }
+
+
+    /**
+     * <p>Submit the page and validate the results.</p>
+     */
+    public void testSubmit() throws Exception {
+
+        // setUp() should have put us on the page
+        assertEquals("View Controller Test", title());
+
+        // Submit the form
+        HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
+        submit(submit);
+
+        // Validate the redispayed content
+        assertEquals("View Controller Test", title());
+        HtmlElement text = element("form:text");
+        assertNotNull(text);
+        assertEquals("init/true/preprocess/true/submit/true/prerender/true/", 
text.asText());
+
+    }
+
+
+}

Modified: 
shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
 (original)
+++ 
shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java
 Sun Jul 16 20:17:18 2006
@@ -37,8 +37,8 @@
 import org.apache.shale.clay.component.Clay;
 import org.apache.shale.clay.config.Globals;
 import org.apache.shale.clay.config.beans.PageNotFoundException;
-import org.apache.shale.view.Constants;
 import org.apache.shale.view.ViewControllerMapper;
+import org.apache.shale.view.faces.FacesConstants;
 import org.apache.shale.view.impl.DefaultViewControllerMapper;
 
 /**
@@ -492,7 +492,7 @@
         if (mapper == null) {
             mapper = (ViewControllerMapper)
               context.getExternalContext().getApplicationMap().
-              get(Constants.VIEW_MAPPER);
+              get(FacesConstants.VIEW_MAPPER);
 
             if (mapper == null) {
                mapper = new DefaultViewControllerMapper();

Modified: 
shale/trunk/shale-core/src/main/java/org/apache/shale/component/Subview.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/component/Subview.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-core/src/main/java/org/apache/shale/component/Subview.java 
(original)
+++ 
shale/trunk/shale-core/src/main/java/org/apache/shale/component/Subview.java 
Sun Jul 16 20:17:18 2006
@@ -27,10 +27,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.shale.util.Messages;
-import org.apache.shale.view.Constants;
 import org.apache.shale.view.ViewController;
 import org.apache.shale.view.faces.CallbacksFactory;
 import org.apache.shale.view.faces.ExceptionHandlerFactory;
+import org.apache.shale.view.faces.FacesConstants;
 import org.apache.shale.view.faces.ViewControllerCallbacks;
 
 /**
@@ -155,10 +155,10 @@
 
         // Schedule this instance for later processing as needed
         Map map = econtext.getRequestMap();
-        List list = (List) map.get(Constants.VIEWS_INITIALIZED);
+        List list = (List) map.get(FacesConstants.VIEWS_INITIALIZED);
         if (list == null) {
             list = new ArrayList();
-            map.put(Constants.VIEWS_INITIALIZED, list);
+            map.put(FacesConstants.VIEWS_INITIALIZED, list);
         }
         list.add(vc);
 
@@ -188,12 +188,12 @@
         if (viewControllerCallbacks == null) {
             viewControllerCallbacks = (ViewControllerCallbacks)
                context.getExternalContext().getApplicationMap().
-               get(Constants.VIEW_CALLBACKS);
+               get(FacesConstants.VIEW_CALLBACKS);
             if (viewControllerCallbacks == null) {
                 viewControllerCallbacks =
                   CallbacksFactory.getInstance().getViewControllerCallbacks();
                 context.getExternalContext().getApplicationMap().
-                put(Constants.VIEW_CALLBACKS, viewControllerCallbacks);
+                put(FacesConstants.VIEW_CALLBACKS, viewControllerCallbacks);
             }
         }
         return viewControllerCallbacks;

Modified: 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/AbstractViewController.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/view/AbstractViewController.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/AbstractViewController.java
 (original)
+++ 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/AbstractViewController.java
 Sun Jul 16 20:17:18 2006
@@ -16,6 +16,9 @@
 
 package org.apache.shale.view;
 
+import javax.faces.context.FacesContext;
+import org.apache.shale.view.faces.FacesConstants;
+
 
 /**
  * <p>[EMAIL PROTECTED] AbstractViewController} is a convenience base 
implementation of
@@ -27,6 +30,25 @@
 
 public class AbstractViewController extends AbstractFacesBean
     implements ViewController {
+
+
+    // ------------------------------------------------------------- 
Constructor
+
+
+    /**
+     * <p>Pre-initialize the <code>postBack</code> property appropriately
+     * if we can.</p>
+     */
+    public AbstractViewController() {
+
+        FacesContext context = FacesContext.getCurrentInstance();
+        if ((context != null)
+            && 
context.getExternalContext().getRequestMap().containsKey(FacesConstants.VIEW_POSTBACK))
 {
+            setPostBack(true);
+        }
+
+    }
+
 
 
     // -------------------------------------------------------------- 
Properties

Modified: 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/Constants.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/view/Constants.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- shale/trunk/shale-core/src/main/java/org/apache/shale/view/Constants.java 
(original)
+++ shale/trunk/shale-core/src/main/java/org/apache/shale/view/Constants.java 
Sun Jul 16 20:17:18 2006
@@ -18,7 +18,8 @@
 
 
 /**
- * <p>Manifest constants related to Shale view support.</p>
+ * <p>Manifest constants related to Shale view support that are relevant
+ * to applications using Shale.</p>
  */
 public final class Constants {
 
@@ -36,67 +37,13 @@
 
 
     /**
-     * <p>Request scope attribute key under which a <code>java.util.List</code>
-     * of exceptions accumulated during the current request processing 
lifecycle
-     * are accumulated.  If there is no such <code>List</code> present, then
-     * no exceptions have been accumulated for the current request.</p>
-     */
-    public static final String EXCEPTIONS_LIST =
-      "org.apache.shale.view.EXCEPTIONS_LIST";
-
-
-    /**
-     * <p>Application scope attribute under which the
-     * <code>ViewControllerCallbacks</code> instance for this application
-     * is stored.</p>
-     */
-    public static final String VIEW_CALLBACKS =
-      "org.apache.shale.view.VIEW_CALLBACKS";
-
-
-    /**
-     * <p>The name of the context initialization parameter that defines the
+     * <p>Name of the context initialization parameter that defines the
      * fully qualified class name of the [EMAIL PROTECTED] 
ViewControllerMapper} to be
      * used is stored.  If not present, the default value is
      * <code>org.apache.shale.view.DefaultViewControllerMapper</code>.</p>
      */
     public static final String VIEW_CONTROLLER_MAPPER =
       "org.apache.shale.view.VIEW_CONTROLLER_MAPPER";
-
-
-    /**
-     * <p>Application scope attribute under which the
-     * [EMAIL PROTECTED] ViewControllerMapper} for translating view identifiers
-     * to class names of the corresponding [EMAIL PROTECTED] ViewController}
-     * is stored.</p>
-     */
-    public static final String VIEW_MAPPER =
-      "org.apache.shale.view.VIEW_MAPPER";
-
-
-    /**
-     * <p>Request scope attribute under which a <code>Boolean.TRUE</code>
-     * flag is stored if this request is a postback.</p>
-     */
-    public static final String VIEW_POSTBACK =
-      "org.apache.shale.view.VIEW_POSTBACK";
-
-
-    /**
-     * <p>Request scope attribute under which the [EMAIL PROTECTED] 
ViewController}
-     * for the view that will actually be rendered (if any) is stored.</p>
-     */
-    public static final String VIEW_RENDERED =
-      "org.apache.shale.view.VIEW_RENDERED";
-
-
-    /**
-     * <p>Request scope attribute under which a <code>List</code>
-     * containing all [EMAIL PROTECTED] ViewController}s that have been 
initialized
-     * for the current request are stored.</p>
-     */
-    public static final String VIEWS_INITIALIZED =
-      "org.apache.shale.view.VIEWS_INITIALIZED";
 
 
 }

Modified: 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java
 (original)
+++ 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ExceptionHandlerImpl.java
 Sun Jul 16 20:17:18 2006
@@ -19,7 +19,6 @@
 import java.util.ArrayList;
 import java.util.List;
 import javax.faces.context.FacesContext;
-import org.apache.shale.view.Constants;
 
 /**
  * <p>Default implementation of the [EMAIL PROTECTED] ExceptionHandler} 
interface.</p>
@@ -54,11 +53,11 @@
             return;
         }
         List list = (List) context.getExternalContext().getRequestMap().
-                get(Constants.EXCEPTIONS_LIST);
+                get(FacesConstants.EXCEPTIONS_LIST);
         if (list == null) {
             list = new ArrayList();
             context.getExternalContext().getRequestMap().
-                    put(Constants.EXCEPTIONS_LIST, list);
+                    put(FacesConstants.EXCEPTIONS_LIST, list);
         }
         list.add(exception);
 

Added: 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/FacesConstants.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/FacesConstants.java?rev=422609&view=auto
==============================================================================
--- 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/FacesConstants.java
 (added)
+++ 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/FacesConstants.java
 Sun Jul 16 20:17:18 2006
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.view.faces;
+
+
+/**
+ * <p>Manifest constants related to Shale view support, which are specific
+ * to the internal implementation and are thus should not be directly
+ * referenced by applications.  Because they are predominantly required only
+ * within the current package, the constants are declared package private
+ * unless outside access is necessary.</p>
+ */
+public final class FacesConstants {
+
+
+    // ------------------------------------------------------------ 
Constructors
+
+
+    /**
+     * <p>Private constructor to avoid instantiation.</p>
+     */
+    private FacesConstants() { }
+
+
+    // ------------------------------------------------------ Manifest 
Constants
+
+
+    /**
+     * <p>Request scope attribute under which a <code>java.util.List</code>
+     * of exceptions accumulated during the current request processing 
lifecycle
+     * are accumulated.  If there is no such <code>List</code> present, then
+     * no exceptions have been accumulated for the current request.</p>
+     */
+    static final String EXCEPTIONS_LIST =
+      "org.apache.shale.view.EXCEPTIONS_LIST";
+
+
+    /**
+     * <p>Application scope attribute under which the
+     * <code>ViewControllerCallbacks</code> instance for this application
+     * is stored.</p>
+     */
+    public static final String VIEW_CALLBACKS =
+      "org.apache.shale.view.VIEW_CALLBACKS";
+
+
+    /**
+     * <p>Request scope attribute under which a <code>List</code>
+     * containing all [EMAIL PROTECTED] ViewController}s that have been 
initialized
+     * for the current request are stored.</p>
+     */
+    public static final String VIEWS_INITIALIZED =
+      "org.apache.shale.view.VIEWS_INITIALIZED";
+
+
+    /**
+     * <p>Application scope attribute under which the
+     * [EMAIL PROTECTED] ViewControllerMapper} for translating view identifiers
+     * to class names of the corresponding [EMAIL PROTECTED] ViewController}
+     * is stored.</p>
+     */
+    public static final String VIEW_MAPPER =
+      "org.apache.shale.view.VIEW_MAPPER";
+
+
+    /**
+     * <p>Request scope attribute under which a <code>Boolean.TRUE</code>
+     * flag is stored if this request is a postback.</p>
+     */
+    public static final String VIEW_POSTBACK =
+      "org.apache.shale.view.VIEW_POSTBACK";
+
+
+    /**
+     * <p>Request scope attribute under which the managed bean name of the
+     * [EMAIL PROTECTED] ViewController} for the view that will actually be 
rendered
+     * (if any) is stored.</p>
+     */
+    static final String VIEW_NAME_RENDERED =
+      "org.apache.shale.view.VIEW_NAME_RENDERED";
+
+
+}

Modified: 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/LifecycleListener.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/LifecycleListener.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/LifecycleListener.java
 (original)
+++ 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/LifecycleListener.java
 Sun Jul 16 20:17:18 2006
@@ -16,9 +16,6 @@
 
 package org.apache.shale.view.faces;
 
-import org.apache.shale.view.AbstractApplicationBean;
-import org.apache.shale.view.AbstractRequestBean;
-import org.apache.shale.view.AbstractSessionBean;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -36,6 +33,11 @@
 import javax.servlet.http.HttpSessionBindingEvent;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.shale.view.AbstractApplicationBean;
+import org.apache.shale.view.AbstractRequestBean;
+import org.apache.shale.view.AbstractSessionBean;
 import org.apache.shale.view.ViewController;
 
 
@@ -70,9 +72,21 @@
      * <p>Create a new lifecycle listener.</p>
      */
     public LifecycleListener() {
+        if (log.isInfoEnabled()) {
+            log.info("Initializing 
org.apache.shale.view.faces.LifecycleListener");
+        }
     }
 
 
+    // -------------------------------------------------------- Static 
Variables
+
+
+    /**
+     * <p>The <code>Log</code> instance for this class.</p>
+     */
+    private static final Log log = LogFactory.getLog(LifecycleListener.class);
+
+
     // ------------------------------------------------------ Manifest 
Constants
 
 
@@ -480,6 +494,11 @@
      */
     public void attributeAdded(ServletRequestAttributeEvent event) {
 
+        if (log.isInfoEnabled()) {
+            log.info("ServletRequestAttributeAdded(" + event.getName()
+              + "," + event.getValue() + ")");
+        }
+
         // Delegate to the Tiger Extensions instance if it exists
         LifecycleListener tiger = tiger();
         if (tiger != null) {
@@ -505,6 +524,13 @@
      */
     public void attributeReplaced(ServletRequestAttributeEvent event) {
 
+        if (log.isInfoEnabled()) {
+            log.info("ServletRequestAttributeReplaced(" + event.getName()
+              + "," + event.getValue()
+              + "," + event.getServletRequest().getAttribute(event.getName())
+              + ")");
+        }
+
         // Delegate to the Tiger Extensions instance if it exists
         LifecycleListener tiger = tiger();
         if (tiger != null) {
@@ -533,6 +559,11 @@
      * @param event Event to be processed
      */
     public void attributeRemoved(ServletRequestAttributeEvent event) {
+
+        if (log.isInfoEnabled()) {
+            log.info("ServletRequestAttributeRemoved(" + event.getName()
+              + "," + event.getValue() + ")");
+        }
 
         // Delegate to the Tiger Extensions instance if it exists
         LifecycleListener tiger = tiger();

Modified: 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewPhaseListener.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewPhaseListener.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewPhaseListener.java
 (original)
+++ 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewPhaseListener.java
 Sun Jul 16 20:17:18 2006
@@ -128,7 +128,7 @@
     private void afterRenderResponse(PhaseEvent event) {
 
         Map map = event.getFacesContext().getExternalContext().getRequestMap();
-        List list = (List) map.get(Constants.VIEWS_INITIALIZED);
+        List list = (List) map.get(FacesConstants.VIEWS_INITIALIZED);
         if (list == null) {
             return;
         }
@@ -137,7 +137,7 @@
             Object vc = vcs.next();
 //            viewControllerCallbacks(event.getFacesContext()).destroy(vc);
         }
-        map.remove(Constants.VIEWS_INITIALIZED);
+        map.remove(FacesConstants.VIEWS_INITIALIZED);
 
     }
 
@@ -151,11 +151,11 @@
     private void afterRestoreView(PhaseEvent event) {
 
         Map map = event.getFacesContext().getExternalContext().getRequestMap();
-        List list = (List) map.get(Constants.VIEWS_INITIALIZED);
+        List list = (List) map.get(FacesConstants.VIEWS_INITIALIZED);
         if (list == null) {
             return;
         }
-        if 
(!event.getFacesContext().getExternalContext().getRequestMap().containsKey(Constants.VIEW_POSTBACK))
 {
+        if 
(!event.getFacesContext().getExternalContext().getRequestMap().containsKey(FacesConstants.VIEW_POSTBACK))
 {
             return;
         }
         Iterator vcs = list.iterator();
@@ -181,7 +181,11 @@
     private void beforeRenderResponse(PhaseEvent event) {
 
         Map map = event.getFacesContext().getExternalContext().getRequestMap();
-        Object vc = map.get(Constants.VIEW_RENDERED);
+        String viewName = (String) map.get(FacesConstants.VIEW_NAME_RENDERED);
+        if (viewName == null) {
+            return;
+        }
+        Object vc = map.get(viewName);
         if (vc == null) {
             return;
         }
@@ -190,7 +194,7 @@
         } catch (Exception e) {
             handleException(e);
         }
-        map.remove(Constants.VIEW_RENDERED);
+        map.remove(FacesConstants.VIEW_NAME_RENDERED);
 
     }
 
@@ -213,11 +217,11 @@
         if (viewControllerCallbacks == null) {
             viewControllerCallbacks = (ViewControllerCallbacks)
                context.getExternalContext().getApplicationMap().
-               get(Constants.VIEW_CALLBACKS);
+               get(FacesConstants.VIEW_CALLBACKS);
             if (viewControllerCallbacks == null) {
                 viewControllerCallbacks = 
CallbacksFactory.getInstance().getViewControllerCallbacks();
                 context.getExternalContext().getApplicationMap().
-                put(Constants.VIEW_CALLBACKS, viewControllerCallbacks);
+                put(FacesConstants.VIEW_CALLBACKS, viewControllerCallbacks);
             }
         }
         return viewControllerCallbacks;

Modified: 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewViewHandler.java
URL: 
http://svn.apache.org/viewvc/shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewViewHandler.java?rev=422609&r1=422608&r2=422609&view=diff
==============================================================================
--- 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewViewHandler.java
 (original)
+++ 
shale/trunk/shale-core/src/main/java/org/apache/shale/view/faces/ViewViewHandler.java
 Sun Jul 16 20:17:18 2006
@@ -186,12 +186,12 @@
         if (mapper == null) {
             mapper = (ViewControllerMapper)
               context.getExternalContext().getApplicationMap().
-              get(Constants.VIEW_MAPPER);
+              get(FacesConstants.VIEW_MAPPER);
         }
         if (mapper == null) {
             mapper = getViewControllerMapperInstance(context);
             context.getExternalContext().getApplicationMap().
-              put(Constants.VIEW_MAPPER, mapper);
+              put(FacesConstants.VIEW_MAPPER, mapper);
         }
         return mapper;
     }
@@ -260,6 +260,13 @@
             return;
         }
 
+        // Cache the postback flag so that it can be used inside
+        // the AbstractViewcontroller implementation
+        if (postBack) {
+            context.getExternalContext().getRequestMap().
+              put(FacesConstants.VIEW_POSTBACK, Boolean.TRUE);
+        }
+
         // Its not the responsibilty of createView method to set the viewId of 
the view
         // (See JSF 1.1 spec. pg. 7-16)
         //String viewId = view.getViewId();
@@ -295,23 +302,18 @@
             return;
         }
 
-        // Configure the instance properties and initialize it
-        if (postBack) {
-            context.getExternalContext().getRequestMap().
-              put(Constants.VIEW_POSTBACK, Boolean.TRUE);
-        }
+        // Set the postBack property on a ViewController instance
         if (vc instanceof ViewController) {
             ((ViewController) vc).setPostBack(postBack);
         }
-        // viewControllerCallbacks(context).init(vc);
 
         // Schedule this instance for later processing as needed
         Map map = context.getExternalContext().getRequestMap();
-        map.put(Constants.VIEW_RENDERED, vc);
-        List list = (List) map.get(Constants.VIEWS_INITIALIZED);
+        map.put(FacesConstants.VIEW_NAME_RENDERED, viewName);
+        List list = (List) map.get(FacesConstants.VIEWS_INITIALIZED);
         if (list == null) {
             list = new ArrayList();
-            map.put(Constants.VIEWS_INITIALIZED, list);
+            map.put(FacesConstants.VIEWS_INITIALIZED, list);
         }
         list.add(vc);
 
@@ -340,11 +342,11 @@
         if (viewControllerCallbacks == null) {
             viewControllerCallbacks = (ViewControllerCallbacks)
                context.getExternalContext().getApplicationMap().
-               get(Constants.VIEW_CALLBACKS);
+               get(FacesConstants.VIEW_CALLBACKS);
             if (viewControllerCallbacks == null) {
                 viewControllerCallbacks = 
CallbacksFactory.getInstance().getViewControllerCallbacks();
                 context.getExternalContext().getApplicationMap().
-                put(Constants.VIEW_CALLBACKS, viewControllerCallbacks);
+                put(FacesConstants.VIEW_CALLBACKS, viewControllerCallbacks);
             }
         }
         return viewControllerCallbacks;


Reply via email to