You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2004/12/23 03:18:03 UTC
svn commit: r123160 - in struts/sandbox/trunk/struts-shale: . src/java/org/apache/shale src/java/org/apache/shale/faces src/java/org/apache/shale/view
Author: craigmcc
Date: Wed Dec 22 18:18:02 2004
New Revision: 123160
URL: http://svn.apache.org/viewcvs?view=rev&rev=123160
Log:
Refinements to the ViewController programming model:
- Add a new preprocess() method that is called, after the component tree
has been restored, if this is a postback request. This method is a
good place to acquire resources that are required to perform event
handling during Apply Request Values through Invoke Application phase
of the JSF request processing lifecycle.
- Rename prepare() to prerender() to be more clear about when this method
is called. It's semantics are not changed.
Modified:
struts/sandbox/trunk/struts-shale/README.html
struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/ViewController.java
struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/faces/ShalePhaseListener.java
struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/view/AbstractViewController.java
Modified: struts/sandbox/trunk/struts-shale/README.html
Url: http://svn.apache.org/viewcvs/struts/sandbox/trunk/struts-shale/README.html?view=diff&rev=123160&p1=struts/sandbox/trunk/struts-shale/README.html&r1=123159&p2=struts/sandbox/trunk/struts-shale/README.html&r2=123160
==============================================================================
--- struts/sandbox/trunk/struts-shale/README.html (original)
+++ struts/sandbox/trunk/struts-shale/README.html Wed Dec 22 18:18:02 2004
@@ -347,7 +347,13 @@
created and framework-defined properties (see above) have been set.
This is a useful place to acquire resources that will be needed for
either a form submit or for rendering a new view.</li>
- <li><strong>prepare()</strong> - Called immediate before the currently
+ <li><strong>preprocess()</strong> - Called after a view has been restored
+ (in JSF terms, this happens at the end of <em>Restore View</em> phase).
+ This method is only called for a postback request, and is useful for
+ acquiring references to model data that will be needed during the
+ processing of the postback (in JSF terms, <em>Apply Request Values</em>
+ through <em>Invoke Application</em> phases).</i>
+ <li><strong>prerender()</strong> - Called immediate before the currently
selected view is rendered (in JSF terms, this happens at the beginning
of <em>Render Response</em> phase, before the <code>encode()</code>
methods of the components have been called). This method is only
Modified: struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/ViewController.java
Url: http://svn.apache.org/viewcvs/struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/ViewController.java?view=diff&rev=123160&p1=struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/ViewController.java&r1=123159&p2=struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/ViewController.java&r2=123160
==============================================================================
--- struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/ViewController.java (original)
+++ struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/ViewController.java Wed Dec 22 18:18:02 2004
@@ -19,7 +19,7 @@
/**
* <p>{@link ViewController} is a "backing bean" interface which adds several
* extension points to the standard JavaServer Faces lifecycle. The extension
- * points help Struts interact with JSF <code>UIComponents</code>.
+ * points help Shale interact with JSF <code>UIComponent</code>s.
* </p>
* <p>
* A "backing bean" represents a convenient place to retrieve and store
@@ -73,7 +73,6 @@
*
* <p>Since the ViewController is a backing bean, you have the option of
* establishing other links with the UIComponents, such as:</p>
- *
* <ul>
* <li>You may use the <code>binding</code> property of any JSF
* <code>UIComponent</code> to establish a linkage between a component
@@ -96,7 +95,7 @@
* <h3>ViewController Lifecycle</h3>
*
* <p>Once you have configured the use of a {@link ViewController} backing bean
- * associated with a JSF view, Struts will provide the following services:</p>
+ * associated with a JSF view, Shale will provide the following services:</p>
* <ul>
* <li>Whenever a JSF view with the appropriate <code>view identifier</code>
* is created or restored, an appropriate instance of the corresponding
@@ -117,19 +116,29 @@
* <li>The <code>init()</code> method will be called, allowing the backing bean
* to acquire data from the model tier as needed to prepare for execution
* of the JSF request processing lifecycle for this view.</li>
- * <li>Standard JSF processing and event handling is performed. For a restored
- * view, the entire lifecycle is executed. For a newly created view, only
- * the <em>Render Response</em> phase is executed.</li>
- * <li>Immediately prior to the <em>Render Response</em> phase, the
- * <code>prepare()</code> method will be called, but only on the
- * {@link ViewController} for whose view JSF will actually perform the
- * rendering. If your {@link ViewController} performed navigation to
- * a different view (either directly via the <code>NavigationHandler</code>
- * or indirectly by virtue of a non-null return from an action method),
- * this method will <strong>not</strong> be called.</p>
+ * <li>For a restored view (i.e. where the <code>postBack</code> property
+ * was set to <code>true</code>, the <code>preprocess()</code> method will
+ * be called after the component tree has been restored by the
+ * <em>Restore View</em> phase. This method will <strong>not</strong>
+ * be called for a view that will only be rendered.</p>
+ * <li>For a restored view, standard JSF processing and event handling occurs
+ * for the <em>Apply Request Values</em> through <em>Invoke Application</em>
+ * phases of the request processing lifecycle. As a side effect, it is
+ * possible that navigation to a different view will have occurred. In
+ * this case, the corresponding <code>ViewController</code> for the new
+ * view will have been instantiated, and its <code>init()</code> method
+ * will have been called, as described above.</li>
+ * <li>For the <code>ViewController</code> whose view will be rendered, the
+ * <code>preprocess()</code> method will be called. If your
+ * <code>ViewController</code> performed navigation to a different view,
+ * this method will <strong>NOT</strong> be called on the original view;
+ * however, it will be called on the <code>ViewController</code> instance
+ * for the page that was navigated to.</li>
* <li>The <code>destroy()</code> method will be called, allowing the backing
* bean to clean up any resources that it has allocated before processing
- * for this HTTP request is completed.</li>
+ * for this HTTP request is completed. In the case where navigation has
+ * occurred, this call will take place on both <code>ViewController</code>
+ * instances that have been initialized.</li>
* </ul>
*
* $Id$
@@ -203,6 +212,20 @@
/**
+ * <p>Called after the component tree has been restored (in <em>Restore
+ * View</em> phase), if the current request is a postback. If this view
+ * is only going to be rendered (because of either direct navigation, or
+ * because this view was navigated to from a different view), this method
+ * will <strong>NOT</strong> be called. As such, this method makes a good
+ * place to acquire information from your model tier that will be required
+ * during the execution of the <em>Apply Request Values</em> through
+ * <em>Invoke Application</em> phases of the request processing lifecycle.
+ * </p>
+ */
+ public void preprocess();
+
+
+ /**
* <p>Called before the <em>Render Response</em> processing for this request
* is performed, whether or not this is a post back request. This method
* will be called only for the view that will actually be rendered. For
@@ -211,7 +234,7 @@
* from your model tier that is required to complete this view's
* presentation.</p>
*/
- public void prepare();
+ public void prerender();
}
Modified: struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/faces/ShalePhaseListener.java
Url: http://svn.apache.org/viewcvs/struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/faces/ShalePhaseListener.java?view=diff&rev=123160&p1=struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/faces/ShalePhaseListener.java&r1=123159&p2=struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/faces/ShalePhaseListener.java&r2=123160
==============================================================================
--- struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/faces/ShalePhaseListener.java (original)
+++ struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/faces/ShalePhaseListener.java Wed Dec 22 18:18:02 2004
@@ -16,6 +16,8 @@
package org.apache.shale.faces;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.shale.ViewController;
import javax.faces.event.PhaseEvent;
@@ -26,8 +28,8 @@
import java.util.Map;
/**
- * <p>{@link ShalePhaseListener} is a JavaServer Faces <code>PhaseListener</code> that implements phase
- * related functionality.</p>
+ * <p>{@link ShalePhaseListener} is a JavaServer Faces <code>PhaseListener</code>
+ * that implements phase related functionality.</p>
*
* $Id$
*/
@@ -35,6 +37,15 @@
public class ShalePhaseListener implements PhaseListener {
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The <code>Log</code> instance for this class.</p>
+ */
+ private static final Log log = LogFactory.getLog(ShalePhaseListener.class);
+
+
// --------------------------------------------------- PhaseListener Methods
@@ -46,8 +57,14 @@
*/
public void afterPhase(PhaseEvent event) {
+ if (log.isTraceEnabled()) {
+ log.trace("afterPhase(" + event.getFacesContext() +
+ "," + event.getPhaseId() + ")");
+ }
PhaseId phaseId = event.getPhaseId();
- if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {
+ if (PhaseId.RESTORE_VIEW.equals(phaseId)) {
+ afterRestoreView(event);
+ } else if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {
afterRenderResponse(event);
}
@@ -62,6 +79,10 @@
*/
public void beforePhase(PhaseEvent event) {
+ if (log.isTraceEnabled()) {
+ log.trace("beforePhase(" + event.getFacesContext() +
+ "," + event.getPhaseId() + ")");
+ }
PhaseId phaseId = event.getPhaseId();
if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {
beforeRenderResponse(event);
@@ -107,9 +128,33 @@
}
+ /**
+ * <p>Call the <code>preprocess()</code> method of the {@link ViewController}
+ * that has been restored, if this is a postback.</p>
+ *
+ * @event <code>PhaseEvent</code> for the current event
+ */
+ private void afterRestoreView(PhaseEvent event) {
+
+ Map map = event.getFacesContext().getExternalContext().getRequestMap();
+ List list = (List) map.get(ShaleConstants.VIEWS_INITIALIZED);
+ if (list == null) {
+ return;
+ }
+ Iterator vcs = list.iterator();
+ while (vcs.hasNext()) {
+ ViewController vc = (ViewController) vcs.next();
+ if (vc.isPostBack()) {
+ vc.preprocess();
+ }
+ }
+
+ }
+
+
/**
- * <p>Call the <code>prepare()</code> method of the {@link ViewController}
+ * <p>Call the <code>prerender()</code> method of the {@link ViewController}
* for the view about to be rendered (if any).</p>
*
* @param event <code>PhaseEvent</code> for the current event
@@ -122,7 +167,7 @@
if (vc == null) {
return;
}
- vc.prepare();
+ vc.prerender();
map.remove(ShaleConstants.VIEW_RENDERED);
}
Modified: struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/view/AbstractViewController.java
Url: http://svn.apache.org/viewcvs/struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/view/AbstractViewController.java?view=diff&rev=123160&p1=struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/view/AbstractViewController.java&r1=123159&p2=struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/view/AbstractViewController.java&r2=123160
==============================================================================
--- struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/view/AbstractViewController.java (original)
+++ struts/sandbox/trunk/struts-shale/src/java/org/apache/shale/view/AbstractViewController.java Wed Dec 22 18:18:02 2004
@@ -93,7 +93,14 @@
/**
* <p>The default implementation does nothing.</p>
*/
- public void prepare() {
+ public void preprocess() {
+ }
+
+
+ /**
+ * <p>The default implementation does nothing.</p>
+ */
+ public void prerender() {
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org