You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2007/10/29 20:44:47 UTC
svn commit: r589824 - in
/myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp:
JspStateManagerImpl.java JspViewHandlerImpl.java
Author: skitching
Date: Mon Oct 29 12:44:46 2007
New Revision: 589824
URL: http://svn.apache.org/viewvc?rev=589824&view=rev
Log:
Documentation changes only.
Modified:
myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
Modified: myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java?rev=589824&r1=589823&r2=589824&view=diff
==============================================================================
--- myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java (original)
+++ myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java Mon Oct 29 12:44:46 2007
@@ -63,18 +63,11 @@
* Only applicable if state saving method is "server" (= default).
* Defines the amount (default = 20) of the latest views are stored in session.
*/
- /**
- * Only applicable if state saving method is "server" (= default).
- * Defines the amount (default = 20) of the latest views are stored in session.
- */
private static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM = "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
/**
* Default value for <code>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</code> context parameter.
*/
- /**
- * Default value for <code>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</code> context parameter.
- */
private static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
/**
@@ -316,22 +309,6 @@
}
}
- /*
- UIViewRoot uiViewRoot = restoreTreeStructure(facesContext, viewId, renderKitId);
- if (uiViewRoot != null)
- {
- uiViewRoot.setViewId(viewId);
-
- restoreComponentState(facesContext, uiViewRoot, renderKitId);
-
- String restoredViewId = uiViewRoot.getViewId();
- if (restoredViewId == null || !(restoredViewId.equals(viewId)))
- {
- if (log.isTraceEnabled()) log.trace("Exiting restoreView - restored view is null.");
- return null;
- }
- }
- */
if (log.isTraceEnabled()) log.trace("Exiting restoreView - "+viewId);
return uiViewRoot;
Modified: myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java?rev=589824&r1=589823&r2=589824&view=diff
==============================================================================
--- myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java (original)
+++ myfaces/core/branches/1_2_1/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java Mon Oct 29 12:44:46 2007
@@ -48,6 +48,59 @@
import java.util.Locale;
/**
+ * Implementation of the ViewHandler interface that knows how to use JSP pages
+ * as the view templating mechanism.
+ * <p>
+ * This implementation works tightly together with the various JSP TagHandler classes
+ * to implement the behaviour mandated by the ViewHandler specification.
+ * <p>
+ * Rendering of a view is done in two parts: first a jsp-generated servlet is invoked
+ * to create or refresh a jsf component tree, then the component tree is walked to generate
+ * the output to send to the user.
+ * <p>
+ * The invoked servlet is the one generated from the jsp file which corresponds to the
+ * viewId of the view being rendered. As is normal for jsp, this servlet alternates between
+ * writing literal text to the response output stream and invoking "tag handler" classes
+ * representing the jsp tags that were present in the page. This servlet is not aware of
+ * JSF at all.
+ * <p>
+ * On the first visit to a view, when each JSF taghandler is invoked, the corresponding
+ * JSF component will not yet exist so it is created and added to the current view tree.
+ * Each JSF taghandler also marks itself as having "buffered body content", which means that
+ * after the start-tag is executed a temporary output stream is installed for the response.
+ * Any output generated by the jsp-servlet therefore gets written into a memory buffer
+ * rather than sent via the network socket to the sender of the request. When the end
+ * of the JSF tag is encountered, the JSF tag checks whether any such body text did exist,
+ * and if so it creates a transient f:verbatim component and inserts it into the component
+ * tree. The final result is that after this "first pass" a component tree exists which has
+ * all the JSF components in it, plus a bunch of auto-generated f:verbatim components that
+ * hold all plain text, or output generated by non-jsf jsp tags. Absolutely NO output has
+ * yet been sent to the real response stream.
+ * <p>
+ * On later visits to the same view, the component tree already exists (has been restored).
+ * However the "verbatim" components holding static text are not present as they were
+ * marked "transient" (not keeping them reduces the amount of memory required to "save state").
+ * Note that these components are not needed for any phase prior to RENDER because they
+ * are not "input" components. When the jsp-generated servlet is executed, JSF taghandlers
+ * that are invoked will simply verify that a corresponding component already exists in the
+ * view-tree rather than creating a new one. However the "body buffering" occurs again, so
+ * that the appropriate transient verbatim components are once again created and inserted into
+ * the tree.
+ * <p>
+ * Regardless of whether the view is new or restored, the rendered output can now be generated
+ * simply by walking the component tree and invoking the encodeBegin/encodeChildren/encodeEnd
+ * methods on each component. The static components simply output their contained text.
+ * <p>
+ * Notes for JSF1.1 users: the new two-phase approach that uses "output buffering" to capture
+ * non-JSF output is rather like wrapping all non-jsf components in an invisible f:verbatim tag.
+ * Although that doesn't sound like a big change, it allows processing to occur in two passes
+ * rather than one. And that means that before any component is rendered the entire component
+ * tree already exists. This solves a number of JSF1.1 problems, including output-ordering
+ * problems between text and jsf components, and errors when using the "for" attribute of a
+ * label to reference a component later in the page. It does introduce a performance penalty;
+ * non-JSF-generated output now gets buffered rather than being streamed directly to the
+ * user.
+ * <p>
* @author Thomas Spiegl (latest modification by $Author$)
* @author Bruno Aranda
* @version $Revision$ $Date$
@@ -89,6 +142,10 @@
return _viewHandlerSupport;
}
+ /**
+ * Get the locales specified as acceptable by the original request, compare them to the
+ * locales supported by this Application and return the best match.
+ */
public Locale calculateLocale(FacesContext facesContext)
{
Application application = facesContext.getApplication();
@@ -133,6 +190,11 @@
}
/**
+ * Create a UIViewRoot object and return it; the returned object has no children.
+ * <p>
+ * As required by the spec, the returned object inherits locale and renderkit settings from
+ * the viewRoot currently configured for the facesContext (if any). This means that on navigation
+ * from one view to another these settings are "inherited".
*/
public UIViewRoot createView(FacesContext facesContext, String viewId)
{
@@ -204,6 +266,13 @@
}
}
+ /**
+ * Return a string containing a webapp-relative URL that the user can invoke
+ * to render the specified view.
+ * <p>
+ * URLs and ViewIds are not quite the same; for example a url of "/foo.jsf"
+ * or "/faces/foo.jsp" may be needed to access the view "/foo.jsp".
+ */
public String getActionURL(FacesContext facesContext, String viewId)
{
return getViewHandlerSupport().calculateActionURL(facesContext, viewId);
@@ -220,6 +289,16 @@
}
+ /**
+ * Generate output to the user by combining the data in the jsp-page specified by viewToRender
+ * with the existing JSF component tree (if any).
+ * <p>
+ * As described in the class documentation, this first runs the jsp-generated servlet to
+ * create or enhance the JSF component tree - including verbatim nodes for any non-jsf
+ * data in that page.
+ * <p>
+ * The component tree is then walked to generate the appropriate output for each component.
+ */
public void renderView(FacesContext facesContext, UIViewRoot viewToRender) throws IOException, FacesException
{
if (viewToRender == null)
@@ -326,12 +405,8 @@
response.flushBuffer();
}
- /**Render the view now - properly setting and resetting the response writer
- *
- * @param facesContext
- * @param newResponseWriter
- * @param viewToRender
- * @throws IOException
+ /**
+ * Render the view now - properly setting and resetting the response writer
*/
private void actuallyRenderView(FacesContext facesContext,
UIViewRoot viewToRender) throws IOException {
@@ -416,6 +491,9 @@
return true;
}
+ /**
+ * Just invoke StateManager.restoreView.
+ */
public UIViewRoot restoreView(FacesContext facesContext, String viewId)
{
Application application = facesContext.getApplication();
@@ -427,8 +505,26 @@
}
/**
- * Writes a state marker that is replaced later by one or more hidden form inputs.
- *
+ * Writes a state marker that is replaced later by one or more hidden form
+ * inputs.
+ * <p>
+ * The problem with html is that the only place to encode client-side state is
+ * in a hidden html input field. However when a form is submitted, only the fields
+ * within a particular form are sent; fields in other forms are not sent. Therefore
+ * the view tree state must be written into every form in the page. This method
+ * is therefore invoked at the end of every form.
+ * <p>
+ * Theoretically the state of a component tree will not change after rendering
+ * starts. Therefore it is possible to create a serialized representation of that
+ * state at the start of the rendering phase (or when first needed) and output it
+ * whenever needed as described above. However this is not currently implemented;
+ * instead the entire page being generated is buffered, and a "marker" string is
+ * output instead of the tree state. After the rendering pass is complete the component
+ * final tree state is computed and the buffer is then post-processed to replace the
+ * "marker" strings with the real data.
+ * <p>
+ * This method also supports "javascript viewstate". TODO: document this.
+ *
* @param facesContext
* @throws IOException
*/