struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r963604 - in /struts/struts2/trunk/plugins/javatemplates/src: main/java/org/apache/struts2/views/java/simple/ test/java/org/apache/struts2/views/java/simple/
Date Tue, 13 Jul 2010 05:54:28 GMT
Author: lukaszlenart
Date: Tue Jul 13 05:54:28 2010
New Revision: 963604

URL: http://svn.apache.org/viewvc?rev=963604&view=rev
Log:
Resolved WW-3463 - added support for dynamic attributes

Added:
    struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/DynamicAttributesHandler.java
Modified:
    struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
    struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractCommonAttributesTest.java
    struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java

Added: struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/DynamicAttributesHandler.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/DynamicAttributesHandler.java?rev=963604&view=auto
==============================================================================
--- struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/DynamicAttributesHandler.java
(added)
+++ struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/DynamicAttributesHandler.java
Tue Jul 13 05:54:28 2010
@@ -0,0 +1,22 @@
+package org.apache.struts2.views.java.simple;
+
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Adds dynamic attributes
+ */
+public class DynamicAttributesHandler extends AbstractTagHandler {
+
+    /* (non-Javadoc)
+     * @see org.apache.struts2.views.java.simple.AbstractTagHandler#start(java.lang.String,
org.apache.struts2.views.java.Attributes)
+     */
+    @Override
+    public void start(String name, Attributes a) throws IOException {
+        a.putAll((Map<String, String>) context.getParameters().get("dynamicAttributes"));
+        super.start(name, a);
+    }
+
+}

Modified: struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java?rev=963604&r1=963603&r2=963604&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
(original)
+++ struts/struts2/trunk/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
Tue Jul 13 05:54:28 2010
@@ -34,28 +34,28 @@ public class SimpleTheme extends Default
     public SimpleTheme() {
         setHandlerFactories(new HashMap<String, List<TagHandlerFactory>>() {
             {
-                put("text", new FactoryList(TextFieldHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("textfield", new FactoryList(TextFieldHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("select", new FactoryList(SelectHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("form", new FactoryList(FormHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
+                put("text", new FactoryList(TextFieldHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("textfield", new FactoryList(TextFieldHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("select", new FactoryList(SelectHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("form", new FactoryList(FormHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
                 put("form-close", new FactoryList(FormHandler.CloseHandler.class));
-                put("a", new FactoryList(AnchorHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
+                put("a", new FactoryList(AnchorHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
                 put("a-close", new FactoryList(AnchorHandler.CloseHandler.class));
-                put("checkbox", new FactoryList(CheckboxHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("file", new FactoryList(FileHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("password", new FactoryList(PasswordHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("label", new FactoryList(LabelHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("reset", new FactoryList(ResetHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
-                put("submit", new FactoryList(SubmitHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
+                put("checkbox", new FactoryList(CheckboxHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("file", new FactoryList(FileHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("password", new FactoryList(PasswordHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("label", new FactoryList(LabelHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("reset", new FactoryList(ResetHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
+                put("submit", new FactoryList(SubmitHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
                 put("submit-close", new FactoryList(SubmitHandler.CloseHandler.class));
-                put("textarea", new FactoryList(TextAreaHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
+                put("textarea", new FactoryList(TextAreaHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
                 put("actionerror", new FactoryList(ActionErrorHandler.class));
                 put("token", new FactoryList(TokenHandler.class));
                 put("actionmessage", new FactoryList(ActionMessageHandler.class));
                 put("head", new FactoryList(HeadHandler.class));
                 put("hidden", new FactoryList(HiddenHandler.class));
                 put("fielderror", new FactoryList(FieldErrorHandler.class));
-                put("div", new FactoryList(DivHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class));
+                put("div", new FactoryList(DivHandler.class, ScriptingEventsHandler.class,
CommonAttributesHandler.class, DynamicAttributesHandler.class));
                 put("div-close", new FactoryList(DivHandler.CloseHandler.class));
                 put("empty", new FactoryList(EmptyHandler.class));
            }

Modified: struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractCommonAttributesTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractCommonAttributesTest.java?rev=963604&r1=963603&r2=963604&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractCommonAttributesTest.java
(original)
+++ struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractCommonAttributesTest.java
Tue Jul 13 05:54:28 2010
@@ -27,7 +27,19 @@ public abstract class AbstractCommonAttr
         theme.renderTag(getTagName(), context);
         String output = writer.getBuffer().toString();
 
-        assertCommongAttrs(output);
+        assertCommonAttrs(output);
     }
 
+    public void testRenderTextFieldDynamicAttrs() throws Exception {
+        UIBean tag = getUIBean();
+
+        applyDynamicAttrs(tag);
+
+        tag.evaluateParams();
+        map.putAll(tag.getParameters());
+        theme.renderTag(getTagName(), context);
+        String output = writer.getBuffer().toString();
+
+        assertDynamicAttrs(output);
+    }
 }

Modified: struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java?rev=963604&r1=963603&r2=963604&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
(original)
+++ struts/struts2/trunk/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AbstractTest.java
Tue Jul 13 05:54:28 2010
@@ -23,6 +23,7 @@ import java.util.Stack;
 public abstract class AbstractTest extends TestCase {
     private Map<String, String> scriptingAttrs = new HashMap<String, String>();
     private Map<String, String> commonAttrs = new HashMap<String, String>();
+    private Map<String, Object> dynamicAttrs = new HashMap<String, Object>();
 
     protected SimpleTheme theme;
 
@@ -60,6 +61,9 @@ public abstract class AbstractTest exten
 
         commonAttrs.put("accesskey", "accesskey_");
 
+        dynamicAttrs.put("data-remote", "data-remote_");
+        dynamicAttrs.put("data-label", "data-label_");
+
         theme = new SimpleTheme();
         writer = new StringWriter();
         map = new HashMap();
@@ -132,6 +136,10 @@ public abstract class AbstractTest exten
         bean.setAccesskey("accesskey_");
     }
 
+    protected void applyDynamicAttrs(UIBean bean) {
+    	bean.setDynamicAttributes(dynamicAttrs);
+    }
+
     protected void assertScriptingAttrs(String str) {
         for (Map.Entry<String, String> entry : scriptingAttrs.entrySet()) {
             String substr = entry.getKey() + "=\"" + entry.getValue() + "\"";
@@ -139,13 +147,20 @@ public abstract class AbstractTest exten
         }
     }
 
-    protected void assertCommongAttrs(String str) {
+    protected void assertCommonAttrs(String str) {
         for (Map.Entry<String, String> entry : commonAttrs.entrySet()) {
             String substr = entry.getKey() + "=\"" + entry.getValue() + "\"";
             assertTrue("String [" + substr + "] was not found in [" + str + "]", str.indexOf(substr)
>= 0);
         }
     }
 
+    protected void assertDynamicAttrs(String str) {
+        for (Map.Entry<String, Object> entry : dynamicAttrs.entrySet()) {
+            String substr = entry.getKey() + "=\"" + entry.getValue() + "\"";
+            assertTrue("String [" + substr + "] was not found in [" + str + "]", str.indexOf(substr)
>= 0);
+        }
+    }
+
     protected Object doFindValue(String expr, Class toType) {
         Object val = stack.findValue(expr);
 



Mime
View raw message