You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2008/02/16 13:55:42 UTC

svn commit: r628286 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/components/ main/java/org/apache/struts2/views/jsp/ui/ test/java/org/apache/struts2/views/jsp/ui/ test/resources/org/apache/struts2/views/jsp/ui/

Author: mrdon
Date: Sat Feb 16 04:55:39 2008
New Revision: 628286

URL: http://svn.apache.org/viewvc?rev=628286&view=rev
Log:
Adding cssErrorClass and cssErrorStyle attributes
WW-771

Added:
    struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt
Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java
    struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java?rev=628286&r1=628285&r2=628286&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java Sat Feb 16 04:55:39 2008
@@ -110,6 +110,18 @@
  *          <td>define html style attribute</td>
  *       </tr>
  *       <tr>
+ *          <td>cssClass</td>
+ *          <td>simple</td>
+ *          <td>String</td>
+ *          <td>error class attribute</td>
+ *       </tr>
+ *       <tr>
+ *          <td>cssStyle</td>
+ *          <td>simple</td>
+ *          <td>String</td>
+ *          <td>error style attribute</td>
+ *       </tr>
+ *       <tr>
  *          <td>title</td>
  *          <td>simple</td>
  *          <td>String</td>
@@ -429,6 +441,8 @@
     protected String id;
     protected String cssClass;
     protected String cssStyle;
+    protected String cssErrorClass;
+    protected String cssErrorStyle;
     protected String disabled;
     protected String label;
     protected String labelPosition;
@@ -466,7 +480,7 @@
     protected String tooltipDelay;
     protected String tooltipCssClass;
     protected String tooltipIconPath;
-    
+
     // dynamic attributes
     protected Map<String,Object> dynamicAttributes = new HashMap<String,Object>();
 
@@ -622,7 +636,7 @@
         if (label != null) {
             addParameter("label", findString(label));
         }
-        
+
         if (labelSeparator != null) {
             addParameter("labelseparator", findString(labelSeparator));
         }
@@ -715,6 +729,14 @@
             addParameter("cssStyle", findString(cssStyle));
         }
 
+        if (cssErrorClass != null) {
+            addParameter("cssErrorClass", findString(cssErrorClass));
+        }
+
+        if (cssErrorStyle != null) {
+            addParameter("cssErrorStyle", findString(cssErrorStyle));
+        }
+
         if (title != null) {
             addParameter("title", findString(title));
         }
@@ -789,37 +811,37 @@
             else {
                 LOG.warn("No ancestor Form found, javascript based tooltip will not work, however standard HTML tooltip using alt and title attribute will still work ");
             }
-            
+
             //TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped
             String  jsTooltipEnabled = (String) getParameters().get("jsTooltipEnabled");
             if (jsTooltipEnabled != null)
                 this.javascriptTooltip = jsTooltipEnabled;
-            
+
             //TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped
             String tooltipIcon = (String) getParameters().get("tooltipIcon");
-            if (tooltipIcon != null) 
+            if (tooltipIcon != null)
                 this.addParameter("tooltipIconPath", tooltipIcon);
             if (this.tooltipIconPath != null)
                 this.addParameter("tooltipIconPath", findString(this.tooltipIconPath));
-            
+
             //TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped
             String tooltipDelayParam = (String) getParameters().get("tooltipDelay");
-            if (tooltipDelayParam != null) 
+            if (tooltipDelayParam != null)
                 this.addParameter("tooltipDelay", tooltipDelayParam);
             if (this.tooltipDelay != null)
                 this.addParameter("tooltipDelay", findString(this.tooltipDelay));
-            
+
             if (this.javascriptTooltip != null) {
                 Boolean jsTooltips = (Boolean) findValue(this.javascriptTooltip, Boolean.class);
                 //TODO use a Boolean model when tooltipConfig is dropped
                 this.addParameter("jsTooltipEnabled", jsTooltips.toString());
-                
+
                 if (form != null)
                     form.addParameter("hasTooltip", jsTooltips);
                 if (this.tooltipCssClass != null)
                     this.addParameter("tooltipCssClass", findString(this.tooltipCssClass));
             }
-            
+
 
         }
 
@@ -994,6 +1016,16 @@
         this.cssStyle = cssStyle;
     }
 
+    @StrutsTagAttribute(description="The css error class to use for element")
+    public void setCssErrorClass(String cssErrorClass) {
+        this.cssErrorClass = cssErrorClass;
+    }
+
+    @StrutsTagAttribute(description="The css error style definitions for element to use")
+    public void setCssErrorStyle(String cssErrorStyle) {
+        this.cssErrorStyle = cssErrorStyle;
+    }
+
     @StrutsTagAttribute(description="Set the html title attribute on rendered html element")
     public void setTitle(String title) {
         this.title = title;
@@ -1008,7 +1040,7 @@
     public void setLabel(String label) {
         this.label = label;
     }
-    
+
     @StrutsTagAttribute(description="String that will be appended to the labe", defaultValue=":")
     public void setLabelSeparator(String labelseparator) {
         this.labelSeparator = labelseparator;

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java?rev=628286&r1=628285&r2=628286&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java Sat Feb 16 04:55:39 2008
@@ -36,7 +36,9 @@
  */
 public abstract class AbstractUITag extends ComponentTagSupport implements DynamicAttributes {
     protected String cssClass;
+    protected String cssErrorClass;
     protected String cssStyle;
+    protected String cssErrorStyle;
     protected String title;
     protected String disabled;
     protected String label;
@@ -66,7 +68,7 @@
     protected String onchange;
     protected String accesskey;
     protected String id;
-    
+
     protected String key;
 
     // tooltip attributes
@@ -85,8 +87,9 @@
 
         UIBean uiBean = (UIBean) component;
         uiBean.setCssClass(cssClass);
-        uiBean.setCssClass(cssClass);
         uiBean.setCssStyle(cssStyle);
+        uiBean.setCssErrorClass(cssErrorClass);
+        uiBean.setCssErrorStyle(cssErrorStyle);
         uiBean.setTitle(title);
         uiBean.setDisabled(disabled);
         uiBean.setLabel(label);
@@ -123,20 +126,28 @@
         uiBean.setAccesskey(accesskey);
         uiBean.setKey(key);
         uiBean.setId(id);
-	
+
         uiBean.setDynamicAttributes(dynamicAttributes);
     }
 
     public void setId(String id) {
         this.id = id;
     }
-    
+
     public void setCssClass(String cssClass) {
         this.cssClass = cssClass;
     }
 
     public void setCssStyle(String cssStyle) {
         this.cssStyle = cssStyle;
+    }
+
+    public void setCssErrorClass(String cssErrorClass) {
+        this.cssErrorClass = cssErrorClass;
+    }
+
+    public void setCssErrorStyle(String cssErrorStyle) {
+        this.cssErrorStyle = cssErrorStyle;
     }
 
     public void setTitle(String title) {

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java?rev=628286&r1=628285&r2=628286&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java Sat Feb 16 04:55:39 2008
@@ -21,6 +21,8 @@
 package org.apache.struts2.views.jsp.ui;
 
 import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
 
 import org.apache.struts2.TestAction;
 import org.apache.struts2.views.jsp.AbstractUITagTest;
@@ -130,11 +132,34 @@
         tag.setOndblclick("test();");
         tag.setOnclick("test();");
         tag.setTitle("mytitle");
+        tag.setCssErrorClass("myErrorClass");
 
         tag.doStartTag();
         tag.doEndTag();
 
         verify(CheckboxTag.class.getResource("Checkbox-3.txt"));
+    }
+
+    public void testCheckedWithErrorStyle() throws Exception {
+        TestAction testAction = (TestAction) action;
+        testAction.setFoo("true");
+        testAction.addFieldError("foo", "Some Foo Error");
+        testAction.addFieldError("foo", "Another Foo Error");
+
+        CheckboxTag tag = new CheckboxTag();
+        tag.setPageContext(pageContext);
+        tag.setLabel("mylabel");
+        tag.setName("foo");
+        tag.setFieldValue("baz");
+        tag.setOndblclick("test();");
+        tag.setOnclick("test();");
+        tag.setTitle("mytitle");
+        tag.setCssErrorStyle("color:red");
+
+        tag.doStartTag();
+        tag.doEndTag();
+
+        verify(CheckboxTag.class.getResource("Checkbox-33.txt"));
     }
 
     public void testUnchecked() throws Exception {

Modified: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt?rev=628286&r1=628285&r2=628286&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt (original)
+++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt Sat Feb 16 04:55:39 2008
@@ -9,7 +9,7 @@
 	
 	</td>
     <td valign="top" align="left">
-          <input type="checkbox" name="foo" value="baz" checked="checked" id="foo" title="mytitle" onclick="test();" ondblclick="test();"/>
+          <input type="checkbox" name="foo" value="baz" checked="checked" id="foo" class="myErrorClass" title="mytitle" onclick="test();" ondblclick="test();"/>
           <input type="hidden" name="__checkbox_foo" value="baz"/>
           <label for="foo" class="checkboxErrorLabel">mylabel</label>
     </td>

Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt?rev=628286&view=auto
==============================================================================
--- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt (added)
+++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt Sat Feb 16 04:55:39 2008
@@ -0,0 +1,16 @@
+<tr errorFor="foo">
+    <td align="left" valign="top" colspan="2"><span class="errorMessage">Some Foo Error</span></td>
+</tr>
+<tr errorFor="foo">
+    <td align="left" valign="top" colspan="2"><span class="errorMessage">Another Foo Error</span></td>
+</tr>
+<tr>
+	<td valign="top" align="right">
+	
+	</td>
+    <td valign="top" align="left">
+          <input type="checkbox" name="foo" value="baz" checked="checked" id="foo" style="color:red" title="mytitle" onclick="test();" ondblclick="test();"/>
+          <input type="hidden" name="__checkbox_foo" value="baz"/>
+          <label for="foo" class="checkboxErrorLabel">mylabel</label>
+    </td>
+</tr>