shale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gvanma...@apache.org
Subject svn commit: r472598 - in /shale/framework/trunk/shale-clay/src: main/java/org/apache/shale/clay/component/chain/ main/resources/META-INF/ test/java/org/apache/shale/clay/config/ test/resources/org/apache/shale/clay/config/
Date Wed, 08 Nov 2006 19:13:13 GMT
Author: gvanmatre
Date: Wed Nov  8 11:13:12 2006
New Revision: 472598

URL: http://svn.apache.org/viewvc?view=rev&rev=472598
Log:
Clay is not recognizing the converterId attribute when using the generic f:converter (SHALE-328).

Added:
    shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ConverterTestCase.java
  (with props)
    shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter-config.xml
  (with props)
    shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter.html
  (with props)
Modified:
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java
    shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
    shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java?view=diff&rev=472598&r1=472597&r2=472598
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java
(original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/CreateConverterCommand.java
Wed Nov  8 11:13:12 2006
@@ -108,8 +108,19 @@
                 ValueBinding vb = facesContext.getApplication().createValueBinding(expr);
                 converter = (Converter) vb.getValue(facesContext);
             } else {
-                converter = facesContext.getApplication().createConverter(
-                        displayElement.getComponentType());
+                // the default converter id comes for the component type
+                String converterId = displayElement.getComponentType();
+                // check for a converterId attribute override
+                attr = displayElement.getAttribute("converterId");
+                if (attr != null && attr.getValue() != null
+                        && attr.getValue().length() > 0) {
+                    clayContext.setAttribute(attr);
+                    String tmp = getTagUtils().evalString(replaceMnemonic(clayContext));
+                    if (tmp != null && tmp.length() > 0) {
+                        converterId = tmp;
+                    }
+                }
+                converter = facesContext.getApplication().createConverter(converterId);
             }
         } catch (Exception e) {
             log.error(getMessages().getMessage("create.converter.error",

Modified: shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java?view=diff&rev=472598&r1=472597&r2=472598
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
(original)
+++ shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/PropertyValueCommand.java
Wed Nov  8 11:13:12 2006
@@ -24,6 +24,7 @@
 
 import javax.faces.component.UIComponentBase;
 import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
 import javax.faces.el.PropertyNotFoundException;
 import javax.faces.el.ValueBinding;
 
@@ -142,6 +143,11 @@
                 && !(child instanceof UIComponentBase)) {
             return isFinal;
 
+        }
+        // skip trying to set the converterId on a converter
+        if (attributeBean.getName().equals("converterId")
+                && child instanceof Converter) {
+            return isFinal;
         }
         // replace all symbols returning the target attribute value
         String expr = replaceMnemonic(clayContext);

Modified: shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml?view=diff&rev=472598&r1=472597&r2=472598
==============================================================================
--- shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml (original)
+++ shale/framework/trunk/shale-clay/src/main/resources/META-INF/clay-config.xml Wed Nov 
8 11:13:12 2006
@@ -31,7 +31,11 @@
          <set name="binding" bindingType="VB" />
      </attributes>
   </component>
-  <component jsfid="f:converter" extends="converter"/>
+  <component jsfid="f:converter" extends="converter">
+     <attributes>
+         <set name="converterId" bindingType="VB" />
+     </attributes>
+  </component>
   
   <component jsfid="validator" componentType="override">
      <description>Abstract component definition.</description>

Added: shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ConverterTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ConverterTestCase.java?view=auto&rev=472598
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ConverterTestCase.java
(added)
+++ shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/ConverterTestCase.java
Wed Nov  8 11:13:12 2006
@@ -0,0 +1,102 @@
+package org.apache.shale.clay.config;
+
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.html.HtmlOutputLabel;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.BooleanConverter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.shale.clay.component.Clay;
+
+public class ConverterTestCase extends AbstractTestCaseConfig {
+
+    // Construct a new instance of this test case.
+    public ConverterTestCase(String name) {
+        super(name);
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+        return (new TestSuite(ConverterTestCase.class));
+    }
+
+    private Clay clay = null;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        loadConfigFiles("/org/apache/shale/clay/config/converter-config.xml",
+                null);
+
+        // register one of the standard converters
+        facesContext.getApplication().addConverter("javax.faces.Boolean",
+                "javax.faces.convert.BooleanConverter");
+
+        clay = (Clay) application
+                .createComponent("org.apache.shale.clay.component.Clay");
+        clay.setId("test");
+        clay.setJsfid("/org/apache/shale/clay/config/converter.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 testConverterComponentType() {
+        HtmlOutputLabel label = (HtmlOutputLabel) findComponent(clay, "testlabel1");
+        assertNotNull(label);
+        
+        assertNotNull(label.getConverter());
+        assertTrue(label.getConverter() instanceof BooleanConverter);
+    }
+
+    public void testConverterIdOverride() {
+        HtmlOutputLabel label = (HtmlOutputLabel) findComponent(clay, "testlabel2");
+        assertNotNull(label);
+        
+        assertNotNull(label.getConverter());
+        assertTrue(label.getConverter() instanceof BooleanConverter);
+ 
+    }
+    
+    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/ConverterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter-config.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter-config.xml?view=auto&rev=472598
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter-config.xml
(added)
+++ shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter-config.xml
Wed Nov  8 11:13:12 2006
@@ -0,0 +1,44 @@
+<?xml version='1.0' encoding="UTF-8"?>
+
+  <!DOCTYPE view PUBLIC
+      "-//Apache Software Foundation//DTD Shale Clay View Configuration 1.0//EN"
+      "http://shale.apache.org/dtds/clay-config_1_0.dtd">
+
+<!--
+ 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.
+-->
+<view>
+
+    <component jsfid="customBooleanConverter" componentType="javax.faces.Boolean"/>
+	<component jsfid="testlabel1" extends="h:outputLabel"> 
+		   <attributes>
+		      <set name="value" value="true" />		
+		   </attributes>
+		   <converter jsfid="customBooleanConverter"/>
+	</component>
+		
+	<component jsfid="testlabel2" extends="h:outputLabel"> 
+		   <attributes>
+		      <set name="value" value="true" />		
+		   </attributes>
+		   <converter jsfid="f:converter">
+		      <attributes>
+		         <set name="converterId" value="javax.faces.Boolean"/>
+		      </attributes>
+		   </converter>
+	</component>
+	
+</view>

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

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

Added: shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter.html
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter.html?view=auto&rev=472598
==============================================================================
--- shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter.html
(added)
+++ shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/converter.html
Wed Nov  8 11:13:12 2006
@@ -0,0 +1,22 @@
+<!-- ### clay:page charset="UTF-8" /### -->
+<!-- ### clay:remove ### -->
+<!--
+ 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.
+-->
+<!-- ### /clay:remove ### -->
+<label jsfid=testlabel1 for=test id=testlabel1>Mock Label</label>
+<label jsfid=testlabel2 for=test id=testlabel2>Mock Label</label>
+<input type=text id=test>
\ No newline at end of file

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

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



Mime
View raw message