You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/09/09 08:03:29 UTC
svn commit: r812780 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/lifecycle/
main/java/org/apache/myfaces/view/facelets/
main/java/org/apache/myfaces/view/facelets/impl/
test/java/org/apache/myfaces/lifecycle/
Author: lu4242
Date: Wed Sep 9 06:03:28 2009
New Revision: 812780
URL: http://svn.apache.org/viewvc?rev=812780&view=rev
Log:
MYFACES-2345 Add View Parameters feature (start point to allow compiler build facelet used to build view metadata, and fix on RestoreViewExecutor)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletFactory.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java?rev=812780&r1=812779&r2=812780&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java Wed Sep 9 06:03:28 2009
@@ -18,14 +18,19 @@
*/
package org.apache.myfaces.lifecycle;
+import java.util.Collection;
+
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.application.ViewExpiredException;
import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewParameter;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.faces.event.PostAddToViewEvent;
+import javax.faces.view.ViewDeclarationLanguage;
+import javax.faces.view.ViewMetadata;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -77,10 +82,6 @@
String viewId = restoreViewSupport.calculateViewId(facesContext);
- // TODO: JSF 2.0 spec section 2.5.5 if the browser issues a GET request with query parameters,
- // no state is restored but full lifecycle minus invoke application should happen
- // if query parameters are set!
-
// Determine if this request is a postback or initial request
if (restoreViewSupport.isPostback(facesContext))
{ // If the request is a postback
@@ -108,28 +109,59 @@
{ // If the request is a non-postback
if (log.isTraceEnabled())
log.trace("Request is not a postback. New UIViewRoot will be created");
-
- // call ViewHandler.createView(), passing the FacesContext instance for the current request and
- // the view identifier
- viewRoot = viewHandler.createView(facesContext, viewId);
-
- // Subscribe the newly created UIViewRoot instance to the AfterAddToParent event, passing the
- // UIViewRoot instance itself as the listener.
- viewRoot.subscribeToEvent(PostAddToViewEvent.class, viewRoot);
-
- // Store the new UIViewRoot instance in the FacesContext.
- facesContext.setViewRoot(viewRoot);
- // Call renderResponse() on the FacesContext.
- facesContext.renderResponse();
+ ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(facesContext, viewId);
- // Publish an AfterAddToParent event with the created UIViewRoot as the event source.
- application.publishEvent(facesContext, PostAddToViewEvent.class, viewRoot);
+ if (vdl != null)
+ {
+ ViewMetadata metadata = vdl.getViewMetadata(facesContext, viewId);
+
+ Collection<UIViewParameter> viewParameters = null;
+
+ if (metadata != null)
+ {
+ viewRoot = metadata.createMetadataView(facesContext);
+
+ if (viewRoot != null)
+ {
+ viewParameters = metadata.getViewParameters(viewRoot);
+ }
+ }
+
+ // call ViewHandler.createView(), passing the FacesContext instance for the current request and
+ // the view identifier
+ if (viewRoot == null)
+ {
+ viewRoot = viewHandler.createView(facesContext, viewId);
+ }
+
+ // Subscribe the newly created UIViewRoot instance to the AfterAddToParent event, passing the
+ // UIViewRoot instance itself as the listener.
+ viewRoot.subscribeToEvent(PostAddToViewEvent.class, viewRoot);
+
+ // Store the new UIViewRoot instance in the FacesContext.
+ facesContext.setViewRoot(viewRoot);
+
+ // If viewParameters is not an empty collection DO NOT call renderResponse
+ if ( !(viewParameters != null && !viewParameters.isEmpty()) )
+ {
+ // Call renderResponse() on the FacesContext.
+ facesContext.renderResponse();
+ }
+
+ // Publish an AfterAddToParent event with the created UIViewRoot as the event source.
+ application.publishEvent(facesContext, PostAddToViewEvent.class, viewRoot);
+ }
+ else
+ {
+ //Call renderResponse but do not publish event because no viewRoot is created
+ facesContext.renderResponse();
+ }
}
return false;
}
-
+
protected RestoreViewSupport getRestoreViewSupport()
{
if (_restoreViewSupport == null)
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletFactory.java?rev=812780&r1=812779&r2=812780&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletFactory.java Wed Sep 9 06:03:28 2009
@@ -63,6 +63,37 @@
public abstract Facelet getFacelet(URL url) throws IOException, FaceletException, FacesException, ELException;
/**
+ * Return a Facelet instance as specified by the file at the passed URI. The returned facelet is used
+ * to create view metadata in this form:
+ * <p>
+ * UIViewRoot(in facet javax_faces_metadata(one or many UIViewParameter instances))
+ * </p>
+ * <p>
+ * This method should be called from FaceletViewMetadata.createMetadataView(FacesContext context)
+ * </p>
+ *
+ * @since 2.0
+ * @param uri
+ * @return
+ * @throws IOException
+ */
+ public abstract Facelet getViewMetadataFacelet(String uri) throws IOException;
+
+ /**
+ * Create a Facelet used to create view metadata from the passed URL. This method checks if the
+ * cached Facelet needs to be refreshed before returning. If so, uses the passed URL to build a new instance;
+ *
+ * @since 2.0
+ * @param url source url
+ * @return Facelet instance
+ * @throws IOException
+ * @throws FaceletException
+ * @throws FacesException
+ * @throws ELException
+ */
+ public abstract Facelet getViewMetadataFacelet(URL url) throws IOException, FaceletException, FacesException, ELException;
+
+ /**
* Set the static instance
*
* @param factory
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=812780&r1=812779&r2=812780&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Wed Sep 9 06:03:28 2009
@@ -95,6 +95,7 @@
import org.apache.myfaces.view.facelets.tag.composite.CompositeComponentResourceTagHandler;
import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
import org.apache.myfaces.view.facelets.tag.composite.CompositeResourceLibrary;
+import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
import org.apache.myfaces.view.facelets.tag.ui.UIDebug;
import org.apache.myfaces.view.facelets.util.DevTools;
import org.apache.myfaces.view.facelets.util.ReflectionUtil;
@@ -1450,6 +1451,20 @@
FaceletFactory.setInstance(null);
}
}
+
+ private Facelet _getViewMetadataFacelet(String viewId) throws IOException
+ {
+ // grab our FaceletFactory and create a Facelet used to create view metadata
+ FaceletFactory.setInstance(_faceletFactory);
+ try
+ {
+ return _faceletFactory.getViewMetadataFacelet(viewId);
+ }
+ finally
+ {
+ FaceletFactory.setInstance(null);
+ }
+ }
/**
* Gets the init parameter value from the specified context and instanciate it. If the parameter was not specified,
@@ -1642,7 +1657,7 @@
// FIXME: spec doesn't say that this is necessary, but we blow up later if
// the viewroot isn't available from the FacesContext.
- context.setViewRoot(view);
+ // context.setViewRoot(view);
// TODO: -= Leonardo Uribe =- This part is related to section 2.5.5 of jsf 2.0 spec.
// In theory what we need here is fill UIViewRoot.METADATA_FACET_NAME facet
@@ -1650,7 +1665,13 @@
// ViewHandlerImpl.getRedirectURL() and UIViewRoot.encodeEnd uses them.
// For now, the only way to do this is call buildView(context,view) method, but
// this is a waste of resources. We need to find another way to handle facelets view metadata.
+
+ // Call to buildView causes the view is not created on Render Response phase,
+ // if buildView is called from here all components pass through current lifecycle and only
+ // UIViewParameter instances should be taken into account.
+ // It should be an additional call to buildView on Render Response phase.
buildView(context, view);
+ //_getViewMetadataFacelet(viewId);
return view;
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java?rev=812780&r1=812779&r2=812780&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletFactory.java Wed Sep 9 06:03:28 2009
@@ -276,4 +276,19 @@
throw new FileNotFoundException("Facelet " + alias + " not found at: " + url.toExternalForm());
}
}
+
+ @Override
+ public Facelet getViewMetadataFacelet(String uri) throws IOException
+ {
+ // TODO MYFACES-2345
+ return null;
+ }
+
+ @Override
+ public Facelet getViewMetadataFacelet(URL url) throws IOException,
+ FaceletException, FacesException, ELException
+ {
+ // TODO MYFACES-2345
+ return null;
+ }
}
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java?rev=812780&r1=812779&r2=812780&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java Wed Sep 9 06:03:28 2009
@@ -28,6 +28,7 @@
import javax.faces.component.UIViewRoot;
import javax.faces.event.PhaseId;
import javax.faces.event.PostAddToViewEvent;
+import javax.faces.view.ViewDeclarationLanguage;
import org.apache.myfaces.FacesTestCase;
import org.apache.myfaces.TestRunner;
@@ -87,6 +88,11 @@
UIViewRoot viewRoot = _mocksControl.createMock(UIViewRoot.class);
viewRoot.subscribeToEvent(same(PostAddToViewEvent.class), same(viewRoot));
+ ViewDeclarationLanguage vdl = _mocksControl.createMock(ViewDeclarationLanguage.class);
+ expect(_viewHandler.getViewDeclarationLanguage(same(_facesContext), eq("calculatedViewId")))
+ .andReturn(vdl);
+ expect(vdl.getViewMetadata(same(_facesContext), eq("calculatedViewId")))
+ .andReturn(null);
expect(_viewHandler.createView(same(_facesContext), eq("calculatedViewId"))).andReturn(viewRoot);
_application.publishEvent(same(_facesContext), same(PostAddToViewEvent.class), same(viewRoot));