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/07/23 23:05:44 UTC
svn commit: r797222 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets: ./
impl/ tag/ tag/ui/
Author: lu4242
Date: Thu Jul 23 21:05:44 2009
New Revision: 797222
URL: http://svn.apache.org/viewvc?rev=797222&view=rev
Log:
MYFACES-2293 ui:composition, ui:define and ui:insert component tag handlers does not work as expected
Added:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java (with props)
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/CompositionHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/InsertHandler.java
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java?rev=797222&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java Thu Jul 23 21:05:44 2009
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.myfaces.view.facelets;
+
+import java.io.IOException;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+
+/**
+ * This class contains methods that belongs to original FaceletContext shipped in
+ * facelets code before 2.0, but does not take part from api, so are considered
+ * implementation details. This includes methods related to template handling
+ * feature of facelets (called by ui:composition, ui:define and ui:insert).
+ *
+ * The methods here are only used by the current implementation and the intention
+ * is not expose it as public api.
+ *
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *
+ * @since 2.0
+ */
+public abstract class AbstractFaceletContext extends FaceletContext
+{
+ /**
+ * Push the passed TemplateClient onto the stack for Definition Resolution
+ * @param client
+ * @see TemplateClient
+ */
+ public abstract void pushClient(TemplateClient client);
+
+ /**
+ * Pop the last added TemplateClient
+ * @see TemplateClient
+ */
+ public abstract void popClient(TemplateClient client);
+
+ public abstract void extendClient(TemplateClient client);
+
+ /**
+ * This method will walk through the TemplateClient stack to resolve and
+ * apply the definition for the passed name.
+ * If it's been resolved and applied, this method will return true.
+ *
+ * @param parent the UIComponent to apply to
+ * @param name name or null of the definition you want to apply
+ * @return true if successfully applied, otherwise false
+ * @throws IOException
+ * @throws FaceletException
+ * @throws FacesException
+ * @throws ELException
+ */
+ public abstract boolean includeDefinition(UIComponent parent, String name)
+ throws IOException, FaceletException, FacesException, ELException;
+}
Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/AbstractFaceletContext.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java?rev=797222&r1=797221&r2=797222&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/DefaultFaceletContext.java Thu Jul 23 21:05:44 2009
@@ -22,8 +22,11 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.el.ELContext;
import javax.el.ELException;
@@ -36,7 +39,10 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
+import org.apache.myfaces.view.facelets.TemplateClient;
import org.apache.myfaces.view.facelets.el.DefaultVariableMapper;
/**
@@ -49,7 +55,7 @@
* @author Jacob Hookom
* @version $Id: DefaultFaceletContext.java,v 1.4.4.3 2006/03/25 01:01:53 jhook Exp $
*/
-final class DefaultFaceletContext extends FaceletContext
+final class DefaultFaceletContext extends AbstractFaceletContext
{
private final FacesContext _faces;
@@ -68,10 +74,13 @@
private String _prefix;
private final StringBuilder _uniqueIdBuilder = new StringBuilder(30);
+
+ private final List<TemplateManager> _clients;
public DefaultFaceletContext(DefaultFaceletContext ctx, DefaultFacelet facelet)
{
_ctx = ctx._ctx;
+ _clients = ctx._clients;
_faces = ctx._faces;
_fnMapper = ctx._fnMapper;
_ids = ctx._ids;
@@ -88,6 +97,7 @@
_ctx = faces.getELContext();
_ids = new HashMap<String, Integer>();
_prefixes = new HashMap<Integer, Integer>();
+ _clients = new ArrayList(5);
_faces = faces;
_faceletHierarchy = new ArrayList<DefaultFacelet>(1);
_faceletHierarchy.add(facelet);
@@ -295,7 +305,110 @@
{
return _ctx.getELResolver();
}
+
+ //Begin methods from AbstractFaceletContext
+
+ @Override
+ public void popClient(TemplateClient client)
+ {
+ if (!this._clients.isEmpty())
+ {
+ Iterator<TemplateManager> itr = this._clients.iterator();
+ while (itr.hasNext())
+ {
+ if (itr.next().equals(client))
+ {
+ itr.remove();
+ return;
+ }
+ }
+ }
+ throw new IllegalStateException(client + " not found");
+ }
+
+ @Override
+ public void pushClient(final TemplateClient client)
+ {
+ this._clients.add(0, new TemplateManager(this._facelet, client, true));
+ }
+
+ @Override
+ public void extendClient(final TemplateClient client)
+ {
+ this._clients.add(new TemplateManager(this._facelet, client, false));
+ }
+
+ @Override
+ public boolean includeDefinition(UIComponent parent, String name)
+ throws IOException, FaceletException, FacesException, ELException
+ {
+ boolean found = false;
+ TemplateManager client;
+
+ for (int i = 0, size = this._clients.size(); i < size && !found; i++)
+ {
+ client = ((TemplateManager) this._clients.get(i));
+ if (client.equals(this._facelet))
+ continue;
+ found = client.apply(this, parent, name);
+ }
+
+ return found;
+ }
+
+ private final static class TemplateManager implements TemplateClient
+ {
+ private final DefaultFacelet _owner;
+
+ private final TemplateClient _target;
+ private final boolean _root;
+
+ private final Set<String> _names = new HashSet<String>();
+
+ public TemplateManager(DefaultFacelet owner, TemplateClient target,
+ boolean root)
+ {
+ this._owner = owner;
+ this._target = target;
+ this._root = root;
+ }
+
+ public boolean apply(FaceletContext ctx, UIComponent parent, String name)
+ throws IOException, FacesException, FaceletException,
+ ELException
+ {
+ String testName = (name != null) ? name : "facelets._NULL_DEF_";
+ if (this._names.contains(testName))
+ {
+ return false;
+ }
+ else
+ {
+ this._names.add(testName);
+ boolean found = false;
+ found = this._target.apply(new DefaultFaceletContext(
+ (DefaultFaceletContext) ctx, this._owner), parent, name);
+ this._names.remove(testName);
+ return found;
+ }
+ }
+
+ public boolean equals(Object o)
+ {
+ // System.out.println(this.owner.getAlias() + " == " +
+ // ((DefaultFacelet) o).getAlias());
+ return this._owner == o || this._target == o;
+ }
+
+ public boolean isRoot()
+ {
+ return this._root;
+ }
+ }
+
+ //End methods from AbstractFaceletContext
+
/**
* {@inheritDoc}
*/
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java?rev=797222&r1=797221&r2=797222&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java Thu Jul 23 21:05:44 2009
@@ -36,6 +36,7 @@
import javax.faces.view.facelets.TagException;
import javax.faces.view.facelets.TagHandler;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.TemplateClient;
import org.apache.myfaces.view.facelets.el.VariableMapperWrapper;
import org.apache.myfaces.view.facelets.tag.ui.DefineHandler;
@@ -104,10 +105,11 @@
ctx.setVariableMapper(varMapper);
}
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
// eval include
try
{
- //ctx.pushClient(this);
+ actx.pushClient(this);
ctx.includeFacelet(parent, this._location);
}
catch (FileNotFoundException e)
@@ -118,7 +120,7 @@
{
// make sure we undo our changes
- //ctx.popClient(this);
+ actx.popClient(this);
ctx.setVariableMapper(orig);
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/CompositionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/CompositionHandler.java?rev=797222&r1=797221&r2=797222&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/CompositionHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/CompositionHandler.java Thu Jul 23 21:05:44 2009
@@ -35,6 +35,7 @@
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.TemplateClient;
import org.apache.myfaces.view.facelets.el.VariableMapperWrapper;
import org.apache.myfaces.view.facelets.tag.TagHandlerUtils;
@@ -120,15 +121,15 @@
_params[i].apply(ctx, parent);
}
}
-
- // ctx.extendClient(this);
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
+ actx.extendClient(this);
try
{
ctx.includeFacelet(parent, _template.getValue(ctx));
}
finally
{
- // ctx.popClient(this);
+ actx.popClient(this);
ctx.setVariableMapper(orig);
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java?rev=797222&r1=797221&r2=797222&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/DecorateHandler.java Thu Jul 23 21:05:44 2009
@@ -35,6 +35,7 @@
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.TemplateClient;
import org.apache.myfaces.view.facelets.el.VariableMapperWrapper;
import org.apache.myfaces.view.facelets.tag.TagHandlerUtils;
@@ -110,7 +111,8 @@
}
}
- // ctx.pushClient(this);
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
+ actx.pushClient(this);
try
{
ctx.includeFacelet(parent, _template.getValue(ctx));
@@ -118,7 +120,7 @@
finally
{
ctx.setVariableMapper(orig);
- // ctx.popClient(this);
+ actx.popClient(this);
}
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/InsertHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/InsertHandler.java?rev=797222&r1=797221&r2=797222&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/InsertHandler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/ui/InsertHandler.java Thu Jul 23 21:05:44 2009
@@ -30,6 +30,7 @@
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler;
+import org.apache.myfaces.view.facelets.AbstractFaceletContext;
import org.apache.myfaces.view.facelets.TemplateClient;
/**
@@ -70,7 +71,21 @@
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
ELException
{
- this.nextHandler.apply(ctx, parent);
+ AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
+ actx.extendClient(this);
+ boolean found = false;
+ try
+ {
+ found = actx.includeDefinition(parent, this.name);
+ }
+ finally
+ {
+ actx.popClient(this);
+ }
+ if (!found)
+ {
+ this.nextHandler.apply(ctx, parent);
+ }
}
public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,