Author: gvanmatre Date: Wed Jan 18 20:36:48 2006 New Revision: 370369 URL: http://svn.apache.org/viewcvs?rev=370369&view=rev Log: Fixed Bug#: 38314 reported by Ryan Wynn.
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/SymbolsTestCase.java Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties?rev=370369&r1=370368&r2=370369&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties Wed Jan 18 20:36:48 2006 @@ -79,6 +79,7 @@ create.component=Child component id: {0}, jsfid: {1} child#: {2} created. create.facet.component=Facet component {0}, jsfid: {1} created. create.component.exists=Child component {0}, jsfid: {1} child#: {2} exists. +create.component.invalid.id=The component symbol substitution failed for id "{0}".\nThe current symbol table includes: {1}. #org.apache.shale.clay.component.chain.CreateConverterCommand create.converter.error=Cannot create Converter {0} @@ -134,9 +135,6 @@ #org.apache.shale.clay.parser.builder.Builder encode.begin=Begin encoding node: {0} encode.end=End encoding node: {0} - -#org.apache.shale.clay.utils.PropUtils -unable.to.set.property.error="Could not set property {0} in bean {1} #org.apache.shale.clay.utils.ClayAmalgam missing.attribute=The "{0}" attribute is required when using the ClayAmalgam.{1}() validator method binding event. Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java?rev=370369&r1=370368&r2=370369&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java Wed Jan 18 20:36:48 2006 @@ -78,6 +78,15 @@ if (facesContext == null) throw new NullPointerException(messages .getMessage("clay.null.facesContext")); + + // create a new scoped symbol table + Map symbolTable = new TreeMap(); + // inherit the parents symbols + symbolTable.putAll(clayContext.getSymbols()); + // override config (XML, HTML) symbols + symbolTable.putAll(displayElement.getSymbols()); + // push to context + clayContext.setSymbols(symbolTable); String id = null; if ((id = displayElement.getId()) == null) @@ -85,6 +94,19 @@ else id = replaceMnemonic(clayContext, id); + //Check to see if the replacement failed. This can happen if the + //symbol is missing. The id will still containing the symbol delimiter + //character. The other scenario is if the value of the symbol is null. + + if (id == null || id.indexOf('@') > -1) { + + if (id == null) + id = displayElement.getId(); + + throw new RuntimeException(messages.getMessage("create.component.invalid.id", + new Object[] {id, symbolTable})); + } + UIComponent child = null; if (displayElement.getFacetName() != null) child = parent.getFacet(displayElement.getFacetName()); @@ -132,23 +154,19 @@ log.debug(messages.getMessage("create.component.exists", new Object[] { id, displayElement.getJsfid(), new Integer(clayContext.getChildIndex()) })); } - - // create a new scoped symbol table - Map symbolTable = new TreeMap(); - // inherit the parents symbols - symbolTable.putAll(clayContext.getSymbols()); - // override config (XML, HTML) symbols - symbolTable.putAll(displayElement.getSymbols()); - // if target is a Clay component it might contain symbols + + // if target is a Clay component it might contain symbols if (child instanceof Clay) { // override symbols from nested clay component symbolTable.putAll(((Clay) child).getSymbols()); // capture current symbols for the root of the nested component ((Clay) child).getSymbols().putAll(symbolTable); + + // push to context + clayContext.setSymbols(symbolTable); } - // push to context - clayContext.setSymbols(symbolTable); + // reassign the child to the converter for the // AssignPropertiesCommand clayContext.setChild(child); Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/SymbolsTestCase.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/SymbolsTestCase.java?rev=370369&r1=370368&r2=370369&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/SymbolsTestCase.java (original) +++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/SymbolsTestCase.java Wed Jan 18 20:36:48 2006 @@ -17,11 +17,14 @@ import java.util.Iterator; +import javax.faces.component.UIComponent; + import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.chain.Command; import org.apache.shale.clay.component.chain.ClayContext; +import org.apache.shale.clay.component.chain.CreateComponentCommand; import org.apache.shale.clay.component.chain.PropertyValueCommand; import org.apache.shale.clay.config.beans.AttributeBean; import org.apache.shale.clay.config.beans.ComponentBean; @@ -122,7 +125,7 @@ // test symbolic property replacement public void testSymbolicProperties() throws Exception { - javax.faces.component.html.HtmlOutputText child = (javax.faces.component.html.HtmlOutputText) + javax.faces.component.html.HtmlOutputText child = (javax.faces.component.html.HtmlOutputText) facesContext.getApplication().createComponent("javax.faces.HtmlOutputText"); assertNotNull("javax.faces.HtmlOutputText", child); @@ -144,7 +147,6 @@ clayContext.setChild(child); clayContext.setAttribute(attr); clayContext.setDisplayElement(displayElement); - // normally done in the AssignChildrenCommand clayContext.setSymbols(displayElement.getSymbols()); //shale core utility class @@ -169,7 +171,6 @@ clayContext.setChild(child); clayContext.setAttribute(attr); clayContext.setDisplayElement(displayElement); - // normally done in the AssignChildrenCommand clayContext.setSymbols(displayElement.getSymbols()); isFinal = command.execute(clayContext); @@ -189,7 +190,6 @@ clayContext.setChild(child); clayContext.setAttribute(attr); clayContext.setDisplayElement(displayElement); - // normally done in the AssignChildrenCommand clayContext.setSymbols(displayElement.getSymbols()); isFinal = command.execute(clayContext); @@ -210,7 +210,6 @@ clayContext.setChild(child); clayContext.setAttribute(attr); clayContext.setDisplayElement(displayElement); - // normally done in the AssignChildrenCommand clayContext.setSymbols(displayElement.getSymbols()); isFinal = command.execute(clayContext); @@ -256,6 +255,101 @@ assertEquals("value = \"rock, rock never stop; rock, rock till ya drop\"", child.getValue(), "rock, rock never stop; rock, rock till ya drop"); + } + + //test component creation using symbols for component id's + public void testCreateComponent()throws Exception { + + UIComponent parent = (UIComponent) + facesContext.getApplication().createComponent("javax.faces.NamingContainer"); + assertNotNull("javax.faces.NamingContainer", parent); + parent.setId("parent"); + + ComponentBean displayElement = new ComponentBean(); + displayElement.setJsfid("inputText"); + displayElement.setComponentType("javax.faces.HtmlOutputText"); + displayElement.setId("@wynn"); + displayElement.addSymbol("@wynn", "test"); + + ClayContext clayContext = new ClayContext(); + clayContext.setFacesContext(facesContext); + clayContext.setParent(parent); + clayContext.setDisplayElement(displayElement); + clayContext.setSymbols(displayElement.getSymbols()); + + // shale core utility class + servletContext.setAttribute(ShaleConstants.TAG_UTILITY_BEAN, new Tags()); + + Command command = new CreateComponentCommand(); + boolean isFinal = command.execute(clayContext); + assertEquals("command finished", isFinal, false); + + UIComponent child = (UIComponent) clayContext.getChild(); + assertNotNull("child", child); + + assertEquals("id = test", child.getId(), "test"); + + + //null component id symbol replacement + parent = (UIComponent) + facesContext.getApplication().createComponent("javax.faces.NamingContainer"); + assertNotNull("javax.faces.NamingContainer", parent); + parent.setId("parent"); + + displayElement = new ComponentBean(); + displayElement.setJsfid("inputText"); + displayElement.setComponentType("javax.faces.HtmlOutputText"); + displayElement.setId("@wynn"); + displayElement.addSymbol("@wynn", null); + + clayContext = new ClayContext(); + clayContext.setFacesContext(facesContext); + clayContext.setParent(parent); + clayContext.setDisplayElement(displayElement); + clayContext.setSymbols(displayElement.getSymbols()); + +// shale core utility class + servletContext.setAttribute(ShaleConstants.TAG_UTILITY_BEAN, new Tags()); + + command = new CreateComponentCommand(); + try { + isFinal = command.execute(clayContext); + assertTrue("id replacement failed", false); + } catch (RuntimeException e) { + assertTrue("null component id", + e.getMessage().startsWith("The component symbol substitution failed for id \"@wynn\"")); + } + + //missing component id symbol replacement + parent = (UIComponent) + facesContext.getApplication().createComponent("javax.faces.NamingContainer"); + assertNotNull("javax.faces.NamingContainer", parent); + parent.setId("parent"); + + displayElement = new ComponentBean(); + displayElement.setJsfid("inputText"); + displayElement.setComponentType("javax.faces.HtmlOutputText"); + displayElement.setId("@wynn"); + + clayContext = new ClayContext(); + clayContext.setFacesContext(facesContext); + clayContext.setParent(parent); + clayContext.setDisplayElement(displayElement); + clayContext.setSymbols(displayElement.getSymbols()); + +// shale core utility class + servletContext.setAttribute(ShaleConstants.TAG_UTILITY_BEAN, new Tags()); + + command = new CreateComponentCommand(); + try { + isFinal = command.execute(clayContext); + assertTrue("id replacement failed", false); + } catch (RuntimeException e) { + assertTrue("missing component id", + e.getMessage().startsWith("The component symbol substitution failed for id \"@wynn\"")); + } + + } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]