From fdc6b27e68df54c86cb2fc6e79840d83be605380 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 18 Dec 2012 19:53:12 +0000 Subject: [PATCH] WW-3929 adds new errorPosition attribute git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1423607 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/struts2/components/UIBean.java | 20 ++++- .../struts2/views/jsp/ui/AbstractUITag.java | 6 ++ .../template/css_xhtml/controlfooter.ftl | 18 +++- .../template/css_xhtml/controlheader-core.ftl | 2 + .../template/xhtml/controlfooter.ftl | 13 +++ .../template/xhtml/controlheader-core.ftl | 6 +- core/src/site/resources/tags/a.html | 8 ++ core/src/site/resources/tags/actionerror.html | 8 ++ .../site/resources/tags/actionmessage.html | 8 ++ core/src/site/resources/tags/ajax/a.html | 8 ++ .../resources/tags/ajax/autocompleter.html | 8 ++ .../resources/tags/ajax/datetimepicker.html | 8 ++ core/src/site/resources/tags/ajax/div.html | 8 ++ core/src/site/resources/tags/ajax/submit.html | 8 ++ .../site/resources/tags/ajax/tabbedpanel.html | 8 ++ .../site/resources/tags/ajax/textarea.html | 8 ++ core/src/site/resources/tags/ajax/tree.html | 8 ++ .../site/resources/tags/ajax/treenode.html | 8 ++ core/src/site/resources/tags/checkbox.html | 8 ++ .../src/site/resources/tags/checkboxlist.html | 8 ++ core/src/site/resources/tags/combobox.html | 8 ++ core/src/site/resources/tags/component.html | 8 ++ core/src/site/resources/tags/debug.html | 8 ++ core/src/site/resources/tags/div.html | 8 ++ .../src/site/resources/tags/doubleselect.html | 8 ++ core/src/site/resources/tags/fielderror.html | 8 ++ core/src/site/resources/tags/file.html | 8 ++ core/src/site/resources/tags/form.html | 8 ++ core/src/site/resources/tags/head.html | 8 ++ core/src/site/resources/tags/hidden.html | 8 ++ .../resources/tags/inputtransferselect.html | 8 ++ core/src/site/resources/tags/label.html | 8 ++ .../resources/tags/optiontransferselect.html | 8 ++ core/src/site/resources/tags/password.html | 8 ++ core/src/site/resources/tags/radio.html | 8 ++ core/src/site/resources/tags/reset.html | 8 ++ core/src/site/resources/tags/select.html | 8 ++ core/src/site/resources/tags/submit.html | 8 ++ core/src/site/resources/tags/textarea.html | 8 ++ core/src/site/resources/tags/textfield.html | 8 ++ core/src/site/resources/tags/token.html | 8 ++ .../src/site/resources/tags/updownselect.html | 8 ++ .../struts2/views/jsp/ui/TextfieldTest.java | 89 ++++++++++++++++++- .../struts2/views/jsp/ui/Textfield-10.txt | 12 +++ .../struts2/views/jsp/ui/Textfield-11.txt | 12 +++ .../struts2/views/jsp/ui/Textfield-8.txt | 13 +++ .../struts2/views/jsp/ui/Textfield-9.txt | 13 +++ 47 files changed, 482 insertions(+), 10 deletions(-) create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-10.txt create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-11.txt create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-8.txt create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-9.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 76b542bb7..f57efdd5d 100644 --- a/core/src/main/java/org/apache/struts2/components/UIBean.java +++ b/core/src/main/java/org/apache/struts2/components/UIBean.java @@ -51,7 +51,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** - * UIBean is the standard superclass of all Struts UI componentns. + * UIBean is the standard superclass of all Struts UI components. * It defines common Struts and html properties all UI components should present for usage. * * @@ -156,6 +156,12 @@ import java.util.concurrent.ConcurrentHashMap; * xhtml * String * define required label position of form element (left/right), default to right + * + * + * errorPosition + * xhtml + * String + * define error position of form element (top|bottom), default to top * * * name @@ -454,6 +460,7 @@ public abstract class UIBean extends Component { protected String labelPosition; protected String labelSeparator; protected String requiredposition; + protected String errorPosition; protected String name; protected String required; protected String tabindex; @@ -666,6 +673,10 @@ public abstract class UIBean extends Component { addParameter("requiredposition", findString(requiredposition)); } + if (errorPosition != null) { + addParameter("errorposition", findString(errorPosition)); + } + if (required != null) { addParameter("required", findValue(required, Boolean.class)); } @@ -1070,6 +1081,11 @@ public abstract class UIBean extends Component { this.requiredposition = requiredposition; } + @StrutsTagAttribute(description="Define error position of form element (top|bottom)") + public void setErrorPosition(String errorPosition) { + this.errorPosition = errorPosition; + } + @StrutsTagAttribute(description="The name to set for element") public void setName(String name) { this.name = name; @@ -1245,4 +1261,4 @@ public abstract class UIBean extends Component { return standardAttributes; } -} \ No newline at end of file +} 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 a84705742..6268f2369 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 @@ -46,6 +46,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam protected String labelSeparator; protected String labelPosition; protected String requiredposition; + protected String errorPosition; protected String name; protected String required; protected String tabindex; @@ -97,6 +98,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam uiBean.setLabelSeparator(labelSeparator); uiBean.setLabelposition(labelPosition); uiBean.setRequiredposition(requiredposition); + uiBean.setErrorPosition(errorPosition); uiBean.setName(name); uiBean.setRequired(required); uiBean.setTabindex(tabindex); @@ -171,6 +173,10 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam this.requiredposition = requiredPosition; } + public void setErrorPosition(String errorPosition) { + this.errorPosition = errorPosition; + } + public void setName(String name) { this.name = name; } diff --git a/core/src/main/resources/template/css_xhtml/controlfooter.ftl b/core/src/main/resources/template/css_xhtml/controlfooter.ftl index 59d6ea273..2f4c66271 100644 --- a/core/src/main/resources/template/css_xhtml/controlfooter.ftl +++ b/core/src/main/resources/template/css_xhtml/controlfooter.ftl @@ -27,4 +27,20 @@ ${parameters.after?if_exists}<#t/> <#else> <#rt/> - +<#if parameters.errorposition?default("top") == 'bottom'> +<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> +<#if hasFieldErrors> +
<#if parameters.id??>id="wwerr_${parameters.id}"<#rt/> class="wwerr"> +<#list fieldErrors[parameters.name] as error> + + <#if parameters.id??> + errorFor="${parameters.id}"<#rt/> + + class="errorMessage"> + ${error?html} +
<#t/> + +<#t/> + + + \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/controlheader-core.ftl b/core/src/main/resources/template/css_xhtml/controlheader-core.ftl index c9cdf11ee..902cda5ac 100644 --- a/core/src/main/resources/template/css_xhtml/controlheader-core.ftl +++ b/core/src/main/resources/template/css_xhtml/controlheader-core.ftl @@ -27,6 +27,7 @@ <#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/>
<#if parameters.id??>id="wwgrp_${parameters.id}"<#rt/> class="wwgrp"> +<#if parameters.errorposition?default("top") == 'top'> <#if hasFieldErrors>
<#if parameters.id??>id="wwerr_${parameters.id}"<#rt/> class="wwerr"> <#list fieldErrors[parameters.name] as error> @@ -40,6 +41,7 @@
<#t/> + <#if parameters.label??> <#if parameters.labelposition?default("top") == 'top'> diff --git a/core/src/main/resources/template/xhtml/controlfooter.ftl b/core/src/main/resources/template/xhtml/controlfooter.ftl index 5072ddb74..37da2f864 100644 --- a/core/src/main/resources/template/xhtml/controlfooter.ftl +++ b/core/src/main/resources/template/xhtml/controlfooter.ftl @@ -23,3 +23,16 @@ ${parameters.after?if_exists}<#t/> <#lt/> +<#if parameters.errorposition?default("top") == 'bottom'> +<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> +<#if hasFieldErrors> +<#list fieldErrors[parameters.name] as error> + + <#rt/> + ${error?html}<#t/> + <#lt/> + + + + + diff --git a/core/src/main/resources/template/xhtml/controlheader-core.ftl b/core/src/main/resources/template/xhtml/controlheader-core.ftl index 35dc8b314..d9417a529 100644 --- a/core/src/main/resources/template/xhtml/controlheader-core.ftl +++ b/core/src/main/resources/template/xhtml/controlheader-core.ftl @@ -25,19 +25,17 @@ This will be done if ActionSupport is used. --> <#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> +<#if parameters.errorposition?default("top") == 'top'> <#if hasFieldErrors> <#list fieldErrors[parameters.name] as error> -<#if parameters.labelposition?default("") == 'top'> - <#rt/> -<#else> <#rt/> - ${error?html}<#t/> <#lt/> + <#-- if the label position is top, then give the label it's own row in the table diff --git a/core/src/site/resources/tags/a.html b/core/src/site/resources/tags/a.html index 60e89f787..b597dc805 100644 --- a/core/src/site/resources/tags/a.html +++ b/core/src/site/resources/tags/a.html @@ -105,6 +105,14 @@ Please do not edit it directly. Boolean Whether to encode parameters + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + escapeAmp false diff --git a/core/src/site/resources/tags/actionerror.html b/core/src/site/resources/tags/actionerror.html index 76aba07d8..3b20cd17a 100644 --- a/core/src/site/resources/tags/actionerror.html +++ b/core/src/site/resources/tags/actionerror.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + escape false diff --git a/core/src/site/resources/tags/actionmessage.html b/core/src/site/resources/tags/actionmessage.html index d18d325e6..f242cd78d 100644 --- a/core/src/site/resources/tags/actionmessage.html +++ b/core/src/site/resources/tags/actionmessage.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + escape false diff --git a/core/src/site/resources/tags/ajax/a.html b/core/src/site/resources/tags/ajax/a.html index 12c765d2c..b5779307d 100644 --- a/core/src/site/resources/tags/ajax/a.html +++ b/core/src/site/resources/tags/ajax/a.html @@ -113,6 +113,14 @@ Please do not edit it directly. String Comma delimmited list of topics that will published after the request(if the request fails) + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + errorText false diff --git a/core/src/site/resources/tags/ajax/autocompleter.html b/core/src/site/resources/tags/ajax/autocompleter.html index 5226afd8d..d0881fb01 100644 --- a/core/src/site/resources/tags/ajax/autocompleter.html +++ b/core/src/site/resources/tags/ajax/autocompleter.html @@ -153,6 +153,14 @@ Please do not edit it directly. String Comma delimmited list of topics that will published after the request(if the request fails) + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + forceValidOption false diff --git a/core/src/site/resources/tags/ajax/datetimepicker.html b/core/src/site/resources/tags/ajax/datetimepicker.html index 630b8382b..d2ff1f82d 100644 --- a/core/src/site/resources/tags/ajax/datetimepicker.html +++ b/core/src/site/resources/tags/ajax/datetimepicker.html @@ -121,6 +121,14 @@ Please do not edit it directly. Date Last available date in the calendar set + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + formatLength false diff --git a/core/src/site/resources/tags/ajax/div.html b/core/src/site/resources/tags/ajax/div.html index 35938c943..a401abbe7 100644 --- a/core/src/site/resources/tags/ajax/div.html +++ b/core/src/site/resources/tags/ajax/div.html @@ -129,6 +129,14 @@ Please do not edit it directly. String Comma delimmited list of topics that will published after the request(if the request fails) + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + errorText false diff --git a/core/src/site/resources/tags/ajax/submit.html b/core/src/site/resources/tags/ajax/submit.html index 3f8d065be..2a69488ef 100644 --- a/core/src/site/resources/tags/ajax/submit.html +++ b/core/src/site/resources/tags/ajax/submit.html @@ -121,6 +121,14 @@ Please do not edit it directly. String Comma delimmited list of topics that will published after the request(if the request fails) + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + errorText false diff --git a/core/src/site/resources/tags/ajax/tabbedpanel.html b/core/src/site/resources/tags/ajax/tabbedpanel.html index 0fb323bd6..00da7c253 100644 --- a/core/src/site/resources/tags/ajax/tabbedpanel.html +++ b/core/src/site/resources/tags/ajax/tabbedpanel.html @@ -121,6 +121,14 @@ Please do not edit it directly. Boolean If doLayout is false, the tab container's height equals the height of the currently selected tab + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id true diff --git a/core/src/site/resources/tags/ajax/textarea.html b/core/src/site/resources/tags/ajax/textarea.html index 42456d6c8..a4f312937 100644 --- a/core/src/site/resources/tags/ajax/textarea.html +++ b/core/src/site/resources/tags/ajax/textarea.html @@ -89,6 +89,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/ajax/tree.html b/core/src/site/resources/tags/ajax/tree.html index 8ce580294..30a01a957 100644 --- a/core/src/site/resources/tags/ajax/tree.html +++ b/core/src/site/resources/tags/ajax/tree.html @@ -113,6 +113,14 @@ Please do not edit it directly. String Comma delimmited list of topics that will published after the request(if the request fails).Only valid if 'href' is set + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + expandIconSrcMinus false diff --git a/core/src/site/resources/tags/ajax/treenode.html b/core/src/site/resources/tags/ajax/treenode.html index ad1d0e69f..4fa5162eb 100644 --- a/core/src/site/resources/tags/ajax/treenode.html +++ b/core/src/site/resources/tags/ajax/treenode.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/checkbox.html b/core/src/site/resources/tags/checkbox.html index 220d168f3..d8829bb22 100644 --- a/core/src/site/resources/tags/checkbox.html +++ b/core/src/site/resources/tags/checkbox.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + fieldValue false diff --git a/core/src/site/resources/tags/checkboxlist.html b/core/src/site/resources/tags/checkboxlist.html index 94dc2343e..5ac227dff 100644 --- a/core/src/site/resources/tags/checkboxlist.html +++ b/core/src/site/resources/tags/checkboxlist.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/combobox.html b/core/src/site/resources/tags/combobox.html index c946ddbaf..abad6b15f 100644 --- a/core/src/site/resources/tags/combobox.html +++ b/core/src/site/resources/tags/combobox.html @@ -89,6 +89,14 @@ Please do not edit it directly. String Decide if an empty option is to be inserted. Default false. + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + headerKey false diff --git a/core/src/site/resources/tags/component.html b/core/src/site/resources/tags/component.html index 1aa1dff03..3aa1deefb 100644 --- a/core/src/site/resources/tags/component.html +++ b/core/src/site/resources/tags/component.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/debug.html b/core/src/site/resources/tags/debug.html index 38f230dba..1050c6b42 100644 --- a/core/src/site/resources/tags/debug.html +++ b/core/src/site/resources/tags/debug.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/div.html b/core/src/site/resources/tags/div.html index 693e1c0dd..8c17b3007 100644 --- a/core/src/site/resources/tags/div.html +++ b/core/src/site/resources/tags/div.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/doubleselect.html b/core/src/site/resources/tags/doubleselect.html index b8c1abab0..de9978e21 100644 --- a/core/src/site/resources/tags/doubleselect.html +++ b/core/src/site/resources/tags/doubleselect.html @@ -345,6 +345,14 @@ Please do not edit it directly. Boolean Decides of an empty option is to be inserted in the second list + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + formName false diff --git a/core/src/site/resources/tags/fielderror.html b/core/src/site/resources/tags/fielderror.html index d5462d463..6e34f4e30 100644 --- a/core/src/site/resources/tags/fielderror.html +++ b/core/src/site/resources/tags/fielderror.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + escape false diff --git a/core/src/site/resources/tags/file.html b/core/src/site/resources/tags/file.html index 28a314b51..18cb72ad1 100644 --- a/core/src/site/resources/tags/file.html +++ b/core/src/site/resources/tags/file.html @@ -89,6 +89,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/form.html b/core/src/site/resources/tags/form.html index 803e3faa4..9e168a44b 100644 --- a/core/src/site/resources/tags/form.html +++ b/core/src/site/resources/tags/form.html @@ -105,6 +105,14 @@ Please do not edit it directly. String HTML form enctype attribute + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + focusElement false diff --git a/core/src/site/resources/tags/head.html b/core/src/site/resources/tags/head.html index be3d03ae8..459968f92 100644 --- a/core/src/site/resources/tags/head.html +++ b/core/src/site/resources/tags/head.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/hidden.html b/core/src/site/resources/tags/hidden.html index fef121d8a..7bae9ba1f 100644 --- a/core/src/site/resources/tags/hidden.html +++ b/core/src/site/resources/tags/hidden.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/inputtransferselect.html b/core/src/site/resources/tags/inputtransferselect.html index ba72da100..d90038d15 100644 --- a/core/src/site/resources/tags/inputtransferselect.html +++ b/core/src/site/resources/tags/inputtransferselect.html @@ -129,6 +129,14 @@ Please do not edit it directly. String the label used for the down button + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + headerKey false diff --git a/core/src/site/resources/tags/label.html b/core/src/site/resources/tags/label.html index 3de6623b3..9f406a704 100644 --- a/core/src/site/resources/tags/label.html +++ b/core/src/site/resources/tags/label.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + for false diff --git a/core/src/site/resources/tags/optiontransferselect.html b/core/src/site/resources/tags/optiontransferselect.html index 190aef315..e1d24731b 100644 --- a/core/src/site/resources/tags/optiontransferselect.html +++ b/core/src/site/resources/tags/optiontransferselect.html @@ -481,6 +481,14 @@ Please do not edit it directly. Boolean Decides of an empty option is to be inserted in the second list + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + formName false diff --git a/core/src/site/resources/tags/password.html b/core/src/site/resources/tags/password.html index 53b63d56a..cccfb3be5 100644 --- a/core/src/site/resources/tags/password.html +++ b/core/src/site/resources/tags/password.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/radio.html b/core/src/site/resources/tags/radio.html index 4aa427d0e..d10c2422c 100644 --- a/core/src/site/resources/tags/radio.html +++ b/core/src/site/resources/tags/radio.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/reset.html b/core/src/site/resources/tags/reset.html index 7e746834f..8e8e0f4e6 100644 --- a/core/src/site/resources/tags/reset.html +++ b/core/src/site/resources/tags/reset.html @@ -97,6 +97,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/select.html b/core/src/site/resources/tags/select.html index 5786c976f..f623f834c 100644 --- a/core/src/site/resources/tags/select.html +++ b/core/src/site/resources/tags/select.html @@ -89,6 +89,14 @@ Please do not edit it directly. Boolean Whether or not to add an empty (--) option after the header option + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + headerKey false diff --git a/core/src/site/resources/tags/submit.html b/core/src/site/resources/tags/submit.html index 9e1ce5bd7..f8807d53f 100644 --- a/core/src/site/resources/tags/submit.html +++ b/core/src/site/resources/tags/submit.html @@ -97,6 +97,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/textarea.html b/core/src/site/resources/tags/textarea.html index 0e0a67545..7e8bb6484 100644 --- a/core/src/site/resources/tags/textarea.html +++ b/core/src/site/resources/tags/textarea.html @@ -89,6 +89,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/textfield.html b/core/src/site/resources/tags/textfield.html index 72ba49374..11d00f62f 100644 --- a/core/src/site/resources/tags/textfield.html +++ b/core/src/site/resources/tags/textfield.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/token.html b/core/src/site/resources/tags/token.html index 144163ab5..033d0f55f 100644 --- a/core/src/site/resources/tags/token.html +++ b/core/src/site/resources/tags/token.html @@ -81,6 +81,14 @@ Please do not edit it directly. String Set the html disabled attribute on rendered html element + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + id false diff --git a/core/src/site/resources/tags/updownselect.html b/core/src/site/resources/tags/updownselect.html index dcaaa9810..95e7491dc 100644 --- a/core/src/site/resources/tags/updownselect.html +++ b/core/src/site/resources/tags/updownselect.html @@ -113,6 +113,14 @@ Please do not edit it directly. Boolean Whether or not to add an empty (--) option after the header option + + errorPosition + false + + false + String + Define error position of form element (top|bottom) + headerKey false diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/TextfieldTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/TextfieldTest.java index 7656315d2..e1a81c40b 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/TextfieldTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/TextfieldTest.java @@ -42,8 +42,8 @@ public class TextfieldTest extends AbstractUITagTest { * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()} * as key. */ - protected Map initializedGenericTagTestProperties() { - Map result = super.initializedGenericTagTestProperties(); + protected Map initializedGenericTagTestProperties() { + Map result = super.initializedGenericTagTestProperties(); new PropertyHolder("maxlength", "10").addToMap(result); new PropertyHolder("readonly", "true", "readonly=\"readonly\"").addToMap(result); new PropertyHolder("size", "12").addToMap(result); @@ -120,7 +120,7 @@ public class TextfieldTest extends AbstractUITagTest { testAction.setFoo("bar"); TextFieldModel model = new TextFieldModel(stack, request, response); - HashMap params = new HashMap(); + Map params = new HashMap(); params.put("name", "myname"); params.put("value", "%{foo}"); params.put("size", "10"); @@ -198,4 +198,87 @@ public class TextfieldTest extends AbstractUITagTest { verify(TextFieldTag.class.getResource("Textfield-7.txt")); } + + public void testErrorPositionBottom() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + TextFieldTag tag = new TextFieldTag(); + tag.setPageContext(pageContext); + tag.setId("myId"); + tag.setLabel("mylabel"); + tag.setName("foo"); + tag.setValue("bar"); + tag.setTitle("mytitle"); + tag.setErrorPosition("bottom"); + + testAction.addFieldError("foo", "bar error message"); + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Textfield-8.txt")); + } + + public void testErrorPositionTop() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + TextFieldTag tag = new TextFieldTag(); + tag.setPageContext(pageContext); + tag.setId("myId"); + tag.setLabel("mylabel"); + tag.setName("foo"); + tag.setValue("bar"); + tag.setTitle("mytitle"); + tag.setErrorPosition("top"); + + testAction.addFieldError("foo", "bar error message"); + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Textfield-9.txt")); + } + + public void testErrorPositionBottomCssXhtmlTheme() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + TextFieldTag tag = new TextFieldTag(); + tag.setPageContext(pageContext); + tag.setId("myId"); + tag.setLabel("mylabel"); + tag.setName("foo"); + tag.setValue("bar"); + tag.setTitle("mytitle"); + tag.setErrorPosition("bottom"); + tag.setTheme("css_xhtml"); + + testAction.addFieldError("foo", "bar error message"); + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Textfield-10.txt")); + } + + public void testErrorPositionTopCssXhtmlTheme() throws Exception { + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + TextFieldTag tag = new TextFieldTag(); + tag.setPageContext(pageContext); + tag.setId("myId"); + tag.setLabel("mylabel"); + tag.setName("foo"); + tag.setValue("bar"); + tag.setTitle("mytitle"); + tag.setErrorPosition("top"); + tag.setTheme("css_xhtml"); + + testAction.addFieldError("foo", "bar error message"); + tag.doStartTag(); + tag.doEndTag(); + + verify(TextFieldTag.class.getResource("Textfield-11.txt")); + } + } diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-10.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-10.txt new file mode 100644 index 000000000..448048fa2 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-10.txt @@ -0,0 +1,12 @@ +
+
+ +
+
+
+ +
+
+
barerrormessage
+
+
\ No newline at end of file diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-11.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-11.txt new file mode 100644 index 000000000..4687d5355 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-11.txt @@ -0,0 +1,12 @@ +
+
+
barerrormessage
+
+
+ +
+
+
+ +
+
\ No newline at end of file diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-8.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-8.txt new file mode 100644 index 000000000..e95f855b1 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-8.txt @@ -0,0 +1,13 @@ + + + + + + + + + + + barerrormessage + + \ No newline at end of file diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-9.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-9.txt new file mode 100644 index 000000000..10cd6942b --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textfield-9.txt @@ -0,0 +1,13 @@ + + + barerrormessage + + + + + mylabel: + + + + + \ No newline at end of file