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 2006/10/19 01:37:06 UTC

svn commit: r465422 - in /shale/framework/trunk/shale-clay/src: main/java/org/apache/shale/clay/parser/builder/ test/java/org/apache/shale/clay/config/ test/resources/org/apache/shale/clay/config/

Author: gvanmatre
Date: Wed Oct 18 16:37:05 2006
New Revision: 465422

URL: http://svn.apache.org/viewvc?view=rev&rev=465422
Log:
This is a fix for the Clay implicit anchored tag mapping that was not assigning the href to the component's value attribute.  It was reported by Torsten Krah (SHALE-313).

Added:
    shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java   (with props)
    shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/implicit.html   (with props)
Modified:
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java?view=diff&rev=465422&r1=465421&r2=465422
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java (original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java Wed Oct 18 16:37:05 2006
@@ -20,7 +20,12 @@
  */
 package org.apache.shale.clay.parser.builder;
 
+import org.apache.shale.clay.config.beans.AttributeBean;
+import org.apache.shale.clay.config.beans.ComponentBean;
+import org.apache.shale.clay.config.beans.ElementBean;
+import org.apache.shale.clay.config.beans.SymbolBean;
 import org.apache.shale.clay.parser.Node;
+import org.apache.shale.clay.parser.builder.chain.AnchorBuilderRule;
 
 /**
  * <p>
@@ -67,6 +72,28 @@
      */
     public boolean isChildrenAllowed() {
         return true;
+    }
+
+    /**
+     * <p>Calls super to populate the <code>target</code> config bean with the
+     * html <code>node</code>'s values.  The "href" attribute doesn't have a
+     * corresponding outputLink value so it will become a symbol.  If there
+     * is a "value" attribute, connect the component's "value" to the
+     * "@href" symbol.</p>
+     *
+     * @param node markup node
+     * @param target config bean
+     * @param root parent config bean
+     */
+    protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
+        super.encodeBegin(node, target, root);
+        
+        AttributeBean attr = target.getAttribute("value");
+        SymbolBean symbol = target.getSymbol("href");
+        if (symbol != null && attr != null
+            && attr.getValue() == null || attr.getValue().length() == 0) {
+            attr.setValue("@href");
+        }
     }
 
 }

Added: shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java?view=auto&rev=465422
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java (added)
+++ shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java Wed Oct 18 16:37:05 2006
@@ -0,0 +1,239 @@
+package org.apache.shale.clay.config;
+
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.component.html.HtmlCommandButton;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.component.html.HtmlInputTextarea;
+import javax.faces.component.html.HtmlOutputLabel;
+import javax.faces.component.html.HtmlOutputLink;
+import javax.faces.component.html.HtmlSelectBooleanCheckbox;
+import javax.faces.component.html.HtmlSelectManyMenu;
+import javax.faces.component.html.HtmlSelectOneMenu;
+import javax.faces.component.html.HtmlSelectOneRadio;
+import javax.faces.context.ResponseWriter;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.shale.clay.component.Clay;
+
+public class ImplicitMappingTestCase extends AbstractTestCaseConfig {
+
+    // Construct a new instance of this test case.
+    public ImplicitMappingTestCase(String name) {
+        super(name);
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+        return (new TestSuite(ImplicitMappingTestCase.class));
+    }
+
+    private Clay clay = null;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // done by the startup context listener
+        loadConfigFiles(null, null);
+
+        clay = (Clay) application
+                .createComponent("org.apache.shale.clay.component.Clay");
+        clay.setId("test");
+        clay.setJsfid("/org/apache/shale/clay/config/implicit.html");
+        clay.setManagedBeanName("test");
+
+        // builds a buffer to write the page to
+        StringWriter writer = new StringWriter();
+        // create a buffered response writer
+        ResponseWriter buffResponsewriter = facesContext.getRenderKit()
+                .createResponseWriter(writer, null,
+                        response.getCharacterEncoding());
+        // push buffered writer to the faces context
+        facesContext.setResponseWriter(buffResponsewriter);
+        // start a document
+        buffResponsewriter.startDocument();
+
+        // build subtree
+        clay.encodeBegin(facesContext);
+    }
+
+    public void testForm() throws Exception {
+
+        // form
+        UIComponent widget = findComponent(clay, "logonForm");
+        assertNotNull("UIForm", widget);
+        assertTrue("UIForm", widget instanceof UIForm);
+    }
+
+    public void testLabel() {
+        // label
+        UIComponent widget = findComponent(clay, "usernameLabel");
+        assertNotNull("HtmlOutputLabel", widget);
+        assertTrue("HtmlOutputLabel", widget instanceof HtmlOutputLabel);
+        assertEquals("for", "username", widget.getAttributes().get("for"));
+
+    }
+
+    public void testInputText() {
+        // input text
+        UIComponent widget = findComponent(clay, "username");
+        assertNotNull("HtmlInputText", widget);
+        assertTrue("HtmlInputText", widget instanceof HtmlInputText);
+        assertEquals("size", "16", widget.getAttributes().get("size")
+                .toString());
+
+        ValueBinding vb = widget.getValueBinding("value");
+        assertNotNull("ValueBinding", vb);
+        String exp = vb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("value", "#{test.username}", exp);
+    }
+
+    public void testSubmit() {
+        // submit
+        UIComponent widget = findComponent(clay, "submit");
+        assertNotNull("HtmlCommandButton", widget);
+        assertTrue("HtmlCommandButton", widget instanceof HtmlCommandButton);
+        assertEquals("value", "submit", widget.getAttributes().get("value")
+                .toString());
+
+        MethodBinding mb = ((HtmlCommandButton) widget).getAction();
+        assertNotNull("MethodBinding", mb);
+        String exp = mb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("action", "#{test.save}", exp);
+
+    }
+
+    public void testAnchor() {
+        UIComponent widget = findComponent(clay, "shaleSite");
+        assertNotNull("HtmlOutputLink", widget);
+        assertTrue("HtmlOutputLink", widget instanceof HtmlOutputLink);
+        assertEquals("value", "http://shale.apache.org/", widget
+                .getAttributes().get("value"));
+        assertEquals("target", "_blank", widget.getAttributes().get("target"));
+
+    }
+
+    public void testCheckBox() {
+        UIComponent widget = findComponent(clay, "checkbox");
+        assertNotNull("HtmlSelectBooleanCheckbox", widget);
+        assertTrue("HtmlSelectBooleanCheckbox",
+                widget instanceof HtmlSelectBooleanCheckbox);
+
+        ValueBinding vb = widget.getValueBinding("value");
+        assertNotNull("ValueBinding", vb);
+        String exp = vb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("value", "#{test.shaleRocks}", exp);
+
+    }
+
+    public void testRadio() {
+        UIComponent widget = findComponent(clay, "radio");
+        assertNotNull("HtmlSelectOneRadio", widget);
+        assertTrue("HtmlSelectOneRadio", widget instanceof HtmlSelectOneRadio);
+
+        ValueBinding vb = widget.getValueBinding("value");
+        assertNotNull("ValueBinding", vb);
+        String exp = vb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("value", "#{test.rockType}", exp);
+
+    }
+
+    public void testSelectOne() {
+        UIComponent widget = findComponent(clay, "states");
+        assertNotNull("HtmlSelectOneMenu", widget);
+        assertTrue("HtmlSelectOneMenu", widget instanceof HtmlSelectOneMenu);
+
+        ValueBinding vb = widget.getValueBinding("value");
+        assertNotNull("ValueBinding", vb);
+        String exp = vb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("value", "#{test.state}", exp);
+
+    }
+
+    public void testOption() {
+        UIComponent widget = findComponent(clay, "alabama");
+        assertNotNull("UISelectItem", widget);
+        assertTrue("UISelectItem", widget instanceof UISelectItem);
+        assertEquals("itemLabel", "Alabama", widget.getAttributes().get(
+                "itemLabel"));
+        assertEquals("itemValue", "AL", widget.getAttributes().get("itemValue"));
+    }
+
+    public void testSelectMany() {
+        UIComponent widget = findComponent(clay, "multiStates");
+        assertNotNull("HtmlSelectManyMenu", widget);
+        assertTrue("HtmlSelectManyMenu", widget instanceof HtmlSelectManyMenu);
+
+        ValueBinding vb = widget.getValueBinding("value");
+        assertNotNull("ValueBinding", vb);
+        String exp = vb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("value", "#{test.state}", exp);
+
+    }
+
+    public void testOptions() {
+        UIComponent widget = findComponent(clay, "stateOptions");
+        assertNotNull("UISelectItems", widget);
+        assertTrue("UISelectItems", widget instanceof UISelectItems);
+
+        ValueBinding vb = widget.getValueBinding("value");
+        assertNotNull("ValueBinding", vb);
+        String exp = vb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("value", "#{test.states}", exp);
+
+    }
+
+    public void testTextArea() {
+        UIComponent widget = findComponent(clay, "textArea");
+        assertNotNull("HtmlInputTextarea", widget);
+        assertTrue("HtmlInputTextarea", widget instanceof HtmlInputTextarea);
+
+        ValueBinding vb = widget.getValueBinding("value");
+        assertNotNull("ValueBinding", vb);
+        String exp = vb.getExpressionString();
+        assertNotNull("Expression String", exp);
+        assertEquals("value", "#{test.textarea}", exp);
+
+        assertEquals("rows", "10", widget.getAttributes().get("rows")
+                .toString());
+
+    }
+
+    private UIComponent findComponent(UIComponent parent, String id) {
+        if (parent == null) {
+            return null;
+        }
+
+        if (parent.getId() != null && parent.getId().equals(id)) {
+            return parent;
+        } else {
+            Iterator ci = parent.getChildren().iterator();
+            while (ci.hasNext()) {
+                UIComponent child = (UIComponent) ci.next();
+                UIComponent target = findComponent(child, id);
+                if (target != null) {
+                    return target;
+                }
+            }
+        }
+
+        return null;
+    }
+
+}

Propchange: shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/implicit.html
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/implicit.html?view=auto&rev=465422
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/implicit.html (added)
+++ shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/implicit.html Wed Oct 18 16:37:05 2006
@@ -0,0 +1,34 @@
+<!-- ### clay:page charset="UTF-8" /### -->
+<!-- ### clay:remove ### -->
+<html>
+<head>
+  <title>Mock Logon Title</title>
+</head>
+<body>
+<!-- ### /clay:remove ### -->
+<form id="logonForm">
+   <label id="usernameLabel" for="username"> Mock User Name Label: </label>
+   <input id="username" type="text" size="16" value="#{@managed-bean-name.username}"/>
+   <input id="submit" type="SUBMIT" value="submit" action="#{@managed-bean-name.save}"/>
+   <a id="shaleSite" href="http://shale.apache.org/" target="_blank">Apache Shale</a>   
+   <input id=checkbox type=checkbox value=#{@managed-bean-name.shaleRocks}>
+   <input id=radio type=radio value=#{@managed-bean-name.rockType}>
+   <select id="states" value="#{@managed-bean-name.state}">
+      <option id="alabama" value=AL>Alabama</option>
+   </select>
+   <select id=multiStates multiple value="#{@managed-bean-name.state}">
+       <!-- has to be a well formed option with no children to be a selectItems -->
+       <option id="stateOptions" value="#{@managed-bean-name.states}"/>
+   </select>
+   <textarea id="textArea" value="#{@managed-bean-name.textarea}" rows=10></textarea> 
+   <!-- 
+      ** not yet supported **
+      <input id="reset" type="RESET" value="reset"/> 
+      <input id="password" type="password" size="16" value="#{@managed-bean-name.password}"/>
+    -->
+
+</form>
+<!-- ### clay:remove ### -->
+</body>
+</html>
+<!-- ### /clay:remove ### -->

Propchange: shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/implicit.html
------------------------------------------------------------------------------
    svn:eol-style = native



Re: svn commit: r465422 - in /shale/framework/trunk/shale-clay/src: main/java/org/apache/shale/clay/parser/builder/ test/java/org/apache/shale/clay/config/ test/resources/org/apache/shale/clay/config/

Posted by Rahul Akolkar <ra...@gmail.com>.
On 10/18/06, gvanmatre@apache.org <gv...@apache.org> wrote:
> Author: gvanmatre
> Date: Wed Oct 18 16:37:05 2006
> New Revision: 465422
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=465422
> Log:
> This is a fix for the Clay implicit anchored tag mapping that was not assigning the href to the component's value attribute.  It was reported by Torsten Krah (SHALE-313).
>
> Added:
>     shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ImplicitMappingTestCase.java   (with props)
>     shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/implicit.html   (with props)
<snip/>

Gary, can you please add ASLv2 headers to new files? Don't worry about
these two -- as part of my todo list, I'm planning on adding them to
any missing source files (my guess would be we're missing these in
quite a few files, probably all in the test and site docs categories.
I plan to drop in the headers when I get a chance since these tend to
get packaged in the source distributions -- unless these are
objections to doing so).

-Rahul