mirror of
https://github.com/apache/struts.git
synced 2026-08-11 09:36:57 +00:00
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
This commit is contained in:
@@ -110,6 +110,18 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
* <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 @@ 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<String,Object> dynamicAttributes = new HashMap<String,Object>();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user