You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by gv...@apache.org on 2007/03/11 02:33:37 UTC
svn commit: r516834 - in /shale/framework/trunk/shale-clay/src:
main/java/org/apache/shale/clay/component/
main/java/org/apache/shale/clay/component/chain/
main/java/org/apache/shale/clay/config/beans/ site/xdoc/
test/java/org/apache/shale/clay/config/
Author: gvanmatre
Date: Sat Mar 10 17:33:36 2007
New Revision: 516834
URL: http://svn.apache.org/viewvc?view=rev&rev=516834
Log:
This fix handles the different behavior of the UIViewRoot component between various versions of JSF. The problem was reported by Richard Eggert (SHALE-418). This also includes a typo in the Clay documentation (SHALE-411).
Modified:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/Clay.java
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/ClayContext.java
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
shale/framework/trunk/shale-clay/src/site/xdoc/index.xml
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/AssignViewRootTestCase.java
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/SymbolsTestCase.java
Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/Clay.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/Clay.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/Clay.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/Clay.java Sat Mar 10 17:33:36 2007
@@ -25,6 +25,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
+import java.util.TreeSet;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
@@ -363,6 +364,7 @@
clayContext.setDisplayElement(getDisplayElementRoot());
clayContext.setJsfid(getJsfid());
clayContext.setFacesContext(getFacesContext());
+ clayContext.setJspIds(new TreeSet());
Map symbolTable = new TreeMap();
symbolTable.putAll(getDisplayElementRoot().getSymbols());
Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java Sat Mar 10 17:33:36 2007
@@ -27,6 +27,7 @@
import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
+import org.apache.shale.clay.component.Clay;
import org.apache.shale.clay.config.Globals;
import org.apache.shale.clay.config.beans.ComponentBean;
@@ -84,6 +85,7 @@
subContext.setParent(parent);
subContext.setChild(null);
subContext.setChildIndex(childIndex);
+ subContext.setJspIds(clayContext.getJspIds());
Catalog catalog = getCatalog();
Command command = catalog
@@ -97,7 +99,27 @@
++childIndex;
}
}
-
+
+ //clay manages its own subtree; components that
+ //renders children still do not build their own
+ //composition. clay does both, build its own subtree
+ //and renders its own children.
+
+ if (!(parent instanceof Clay)) {
+ // remove any components not represented by the metadata graph
+ for (int i = parent.getChildCount() - 1; i > -1; i--) {
+ UIComponent child = (UIComponent) parent.getChildren().get(i);
+ Long jspId = (Long) child.getAttributes().get(
+ Globals.CLAY_JSPID_ATTRIBUTE);
+ if (jspId != null
+ && !clayContext.getJspIds().contains(jspId)) {
+ parent.getChildren().remove(i);
+ child.setParent(null);
+ }
+ }
+ }
+
+
return isFinal;
}
Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/ClayContext.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/ClayContext.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/ClayContext.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/ClayContext.java Sat Mar 10 17:33:36 2007
@@ -22,6 +22,7 @@
import java.util.Map;
import java.util.TreeMap;
+import java.util.TreeSet;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -297,5 +298,28 @@
*/
public void setChildIndex(int index) {
childIndex = index;
+ }
+
+ /**
+ * <p>Each <code>displayElement</code> is given a unique id. This
+ * set represents each {@link ComponentBean} used in the page
+ * composition.</p>
+ */
+ private TreeSet jspIds = null;
+
+ /**
+ * @return the set that represents each <code>displayElement</code> used
+ * to build the target JSF sub componennt tree
+ */
+ public TreeSet getJspIds() {
+ return jspIds;
+ }
+
+ /**
+ * @param graph the set that represents each <code>displayElement</code> used
+ * to build the target JSF sub componennt tree
+ */
+ public void setJspIds(TreeSet graph) {
+ jspIds = graph;
}
}
Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java Sat Mar 10 17:33:36 2007
@@ -105,6 +105,9 @@
realizeSymbols(clayContext);
UIComponent child = null;
+ Long jspId = new Long(displayElement.getJspId());
+ clayContext.getJspIds().add(jspId);
+
String facetName = displayElement.getFacetName();
if (facetName != null) {
facetName = replaceMnemonic(clayContext, facetName);
@@ -113,17 +116,14 @@
child = parent.getFacet(displayElement.getFacetName());
}
if (child == null) {
- child = this.findComponentByJspId(parent, displayElement.getJspId());
+ child = this.findComponentByJspId(parent, jspId);
}
-
- String id = null;
+ // always burn an id; this is to support the early versions of myfaces & RI 1.1
+ // the UIViewRoot didn't persist the sequence that is used by the call to createUniqueId
+ String id = facesContext.getViewRoot().createUniqueId();
if (child == null) {
- id = displayElement.getId();
-
- if (id == null) {
- id = facesContext.getViewRoot().createUniqueId();
- } else {
- id = replaceMnemonic(clayContext, id);
+ if (displayElement.getId() != null) {
+ id = replaceMnemonic(clayContext, displayElement.getId());
}
} else {
id = child.getId();
@@ -169,7 +169,7 @@
}
child.setId(id);
- child.getAttributes().put(Globals.CLAY_JSPID_ATTRIBUTE, displayElement.getJspId());
+ child.getAttributes().put(Globals.CLAY_JSPID_ATTRIBUTE, jspId);
if (facetName != null) {
parent.getFacets().put(facetName, child);
@@ -235,11 +235,11 @@
* @return the child <code>UIComponent</code> if a match is found; otherwise;
* a <code>null</code> value.
*/
- private UIComponent findComponentByJspId(UIComponent parent, String id) {
+ private UIComponent findComponentByJspId(UIComponent parent, Long id) {
Iterator ci = parent.getChildren().iterator();
while (ci.hasNext()) {
UIComponent child = (UIComponent) ci.next();
- String jspId = (String) child.getAttributes().get(Globals.CLAY_JSPID_ATTRIBUTE);
+ Long jspId = (Long) child.getAttributes().get(Globals.CLAY_JSPID_ATTRIBUTE);
if (jspId != null && jspId.equals(id)) {
return child;
}
Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/ComponentBean.java Sat Mar 10 17:33:36 2007
@@ -79,16 +79,18 @@
/**
* <p>Returns a unique id that will stick to the config bean.
+ * It represents its compositional relationship within the subtree.
* This is clay's version of the <code>JspIdConsumer</code>
* in JSP 2.1.</p>
*
* @return unique id for a view element
*/
- public String getJspId() {
+ public long getJspId() {
if (jspId == -1) {
jspId = generateId();
}
- return Long.toString(jspId);
+
+ return jspId;
}
/**
Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/config/beans/TemplateConfigBean.java Sat Mar 10 17:33:36 2007
@@ -75,10 +75,6 @@
//loads the HTML template the first time and when file
//has been modified
watchDog.refresh(false);
- } else {
- //check to see if an existing html template
- //needs reloaded
- watchDog.refresh(false);
}
// returns the cached element
Modified: shale/framework/trunk/shale-clay/src/site/xdoc/index.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/site/xdoc/index.xml?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/site/xdoc/index.xml (original)
+++ shale/framework/trunk/shale-clay/src/site/xdoc/index.xml Sat Mar 10 17:33:36 2007
@@ -353,7 +353,7 @@
</li>
<li><p>The subtree can be formed using a Tapestry like HTML layout. The benefit of using HTML
layout composition is that it allows you to use standard HTML tools. It also promotes
- more rapped development as an HTML prototype can evolve into a dynamic web page. The
+ more rapid development as an HTML prototype can evolve into a dynamic web page. The
HTML elements are bound to corresponding JSF components using a jsfid attribute. This
attribute binds the HTML mock-up with a component declared in the Clay view configuration
files. Some HTML elements, the such as the FORM element, have an implied mapping to a
Modified: shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/AssignViewRootTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/AssignViewRootTestCase.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/AssignViewRootTestCase.java (original)
+++ shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/AssignViewRootTestCase.java Sat Mar 10 17:33:36 2007
@@ -20,13 +20,16 @@
import java.util.Iterator;
import java.util.Locale;
+import javax.faces.FactoryFinder;
import javax.faces.component.UIComponent;
import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKitFactory;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.shale.clay.component.Clay;
+import org.apache.shale.test.mock.MockRenderKit;
public class AssignViewRootTestCase extends AbstractTestCaseConfig {
@@ -51,6 +54,11 @@
public void testAssign1() throws Exception {
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = new MockRenderKit();
+ renderKitFactory.addRenderKit("MY_KIT1", renderKit);
+
buildSubtree("/org/apache/shale/clay/config/viewroot1.html");
String renderKitId = facesContext.getViewRoot().getRenderKitId();
@@ -68,6 +76,11 @@
}
public void testAssign2() throws Exception {
+
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = new MockRenderKit();
+ renderKitFactory.addRenderKit("MY_KIT2", renderKit);
buildSubtree("/org/apache/shale/clay/config/viewroot2.html");
@@ -87,6 +100,11 @@
public void testAssign3() throws Exception {
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = new MockRenderKit();
+ renderKitFactory.addRenderKit("MY_KIT3", renderKit);
+
buildSubtree("/org/apache/shale/clay/config/viewroot3.html");
String renderKitId = facesContext.getViewRoot().getRenderKitId();
@@ -108,6 +126,7 @@
clay.setId("test");
clay.setJsfid(jsfid);
clay.setManagedBeanName("test");
+ facesContext.getViewRoot().getChildren().add(0, clay);
// builds a buffer to write the page to
StringWriter writer = new StringWriter();
Modified: shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/SymbolsTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/SymbolsTestCase.java?view=diff&rev=516834&r1=516833&r2=516834
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/SymbolsTestCase.java (original)
+++ shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/SymbolsTestCase.java Sat Mar 10 17:33:36 2007
@@ -19,6 +19,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
+import java.util.TreeSet;
import javax.faces.component.UIComponent;
@@ -368,6 +369,7 @@
clayContext.setParent(parent);
clayContext.setDisplayElement(displayElement);
clayContext.setSymbols(displayElement.getSymbols());
+ clayContext.setJspIds(new TreeSet());
Command command = new CreateComponentCommand();
boolean isFinal = command.execute(clayContext);
@@ -396,6 +398,7 @@
clayContext.setParent(parent);
clayContext.setDisplayElement(displayElement);
clayContext.setSymbols(displayElement.getSymbols());
+ clayContext.setJspIds(new TreeSet());
command = new CreateComponentCommand();
try {
@@ -422,6 +425,7 @@
clayContext.setParent(parent);
clayContext.setDisplayElement(displayElement);
clayContext.setSymbols(displayElement.getSymbols());
+ clayContext.setJspIds(new TreeSet());
command = new CreateComponentCommand();
try {