From 2ed83ba79c1e18b594830d62ccc044fbdf889c76 Mon Sep 17 00:00:00 2001 From: "Donald J. Brown" Date: Sat, 16 Feb 2008 12:55:39 +0000 Subject: [PATCH] Adding cssErrorClass and cssErrorStyle attributes WW-771 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@628286 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/struts2/components/UIBean.java | 54 +++++++++++++++---- .../struts2/views/jsp/ui/AbstractUITag.java | 19 +++++-- .../struts2/views/jsp/ui/CheckboxTest.java | 25 +++++++++ .../struts2/views/jsp/ui/Checkbox-3.txt | 2 +- .../struts2/views/jsp/ui/Checkbox-33.txt | 16 ++++++ 5 files changed, 100 insertions(+), 16 deletions(-) create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt diff --git a/core/src/main/java/org/apache/struts2/components/UIBean.java b/core/src/main/java/org/apache/struts2/components/UIBean.java index 059d4c5d8..c24d80e03 100644 --- a/core/src/main/java/org/apache/struts2/components/UIBean.java +++ b/core/src/main/java/org/apache/struts2/components/UIBean.java @@ -110,6 +110,18 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory; * define html style attribute * * + * cssClass + * simple + * String + * error class attribute + * + * + * cssStyle + * simple + * String + * error style attribute + * + * * title * simple * String @@ -429,6 +441,8 @@ public abstract class UIBean extends Component { 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 @@ public abstract class UIBean extends Component { protected String tooltipDelay; protected String tooltipCssClass; protected String tooltipIconPath; - + // dynamic attributes protected Map dynamicAttributes = new HashMap(); @@ -622,7 +636,7 @@ public abstract class UIBean extends Component { if (label != null) { addParameter("label", findString(label)); } - + if (labelSeparator != null) { addParameter("labelseparator", findString(labelSeparator)); } @@ -715,6 +729,14 @@ public abstract class UIBean extends Component { 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 @@ public abstract class UIBean extends Component { 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 @@ public abstract class UIBean extends Component { 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 abstract class UIBean extends Component { 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; diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java index ab73e9e98..90be5031b 100644 --- a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java +++ b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java @@ -36,7 +36,9 @@ import org.apache.struts2.views.jsp.ComponentTagSupport; */ 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 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam protected String onchange; protected String accesskey; protected String id; - + protected String key; // tooltip attributes @@ -85,8 +87,9 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam 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,14 +126,14 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam 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; } @@ -139,6 +142,14 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam this.cssStyle = cssStyle; } + public void setCssErrorClass(String cssErrorClass) { + this.cssErrorClass = cssErrorClass; + } + + public void setCssErrorStyle(String cssErrorStyle) { + this.cssErrorStyle = cssErrorStyle; + } + public void setTitle(String title) { this.title = title; } diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java index aeb389574..79d985501 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java @@ -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,6 +132,7 @@ public class CheckboxTest extends AbstractUITagTest { tag.setOndblclick("test();"); tag.setOnclick("test();"); tag.setTitle("mytitle"); + tag.setCssErrorClass("myErrorClass"); tag.doStartTag(); tag.doEndTag(); @@ -137,6 +140,28 @@ public class CheckboxTest extends AbstractUITagTest { 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 { TestAction testAction = (TestAction) action; testAction.setFoo("false"); diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt index 11a5782d3..dc9457ea9 100644 --- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-3.txt @@ -9,7 +9,7 @@ - + diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt new file mode 100644 index 000000000..be23b7a39 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Checkbox-33.txt @@ -0,0 +1,16 @@ + + Some Foo Error + + + Another Foo Error + + + + + + + + + + +