struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r722198 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/components/ main/java/org/apache/struts2/views/jsp/ui/ site/resources/tags/ test/java/org/apache/struts2/views/jsp/ui/ test/resources/org/apache/struts2/views/jsp/ui/
Date Mon, 01 Dec 2008 19:49:00 GMT
Author: musachy
Date: Mon Dec  1 11:49:00 2008
New Revision: 722198

URL: http://svn.apache.org/viewvc?rev=722198&view=rev
Log:
WW-2671 Add fieldName attribute to FieldErrorTag

Thanks to David Evans for the patch

Added:
    struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/fielderror-6.txt
Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FieldError.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FieldErrorTag.java
    struts/struts2/trunk/core/src/site/resources/tags/fielderror.html
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FieldError.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FieldError.java?rev=722198&r1=722197&r2=722198&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FieldError.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/FieldError.java
Mon Dec  1 11:49:00 2008
@@ -21,16 +21,15 @@
 
 package org.apache.struts2.components;
 
-import java.util.ArrayList;
-import java.util.List;
+import com.opensymphony.xwork2.util.ValueStack;
+import org.apache.struts2.components.Param.UnnamedParametric;
+import org.apache.struts2.views.annotations.StrutsTag;
+import org.apache.struts2.views.annotations.StrutsTagAttribute;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
-import org.apache.struts2.views.annotations.StrutsTag;
-import org.apache.struts2.components.Param.UnnamedParametric;
-
-import com.opensymphony.xwork2.util.ValueStack;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * <!-- START SNIPPET: javadoc -->
@@ -66,6 +65,10 @@
  *       ....
  *    &lt;/s:form&gt;
  *
+ *    OR
+ *
+ *    &lt;s:fielderror fieldName="field1" /&gt;
+ *
  * <!-- END SNIPPET: example -->
  * </pre>
  *
@@ -108,5 +111,10 @@
     public List<String> getFieldErrorFieldNames() {
         return errorFieldNames;
     }
+
+    @StrutsTagAttribute(description="Field name for single field attribute usage", type="String")
+    public void setFieldName(String fieldName) {
+        addParameter(fieldName);
+    }
 }
 

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FieldErrorTag.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FieldErrorTag.java?rev=722198&r1=722197&r2=722198&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FieldErrorTag.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/FieldErrorTag.java
Mon Dec  1 11:49:00 2008
@@ -36,8 +36,22 @@
 
     private static final long serialVersionUID = -182532967507726323L;
 
+    protected String fieldName;
+
+
     public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse
res) {
         return new FieldError(stack, req, res);
     }
+
+    protected void populateParams() {
+        super.populateParams();
+
+        FieldError fieldError = ((FieldError) component);
+        fieldError.setFieldName(this.fieldName);
+    }
+
+    public void setFieldName(String fieldName) {
+        this.fieldName = fieldName;
+    }
 }
 

Modified: struts/struts2/trunk/core/src/site/resources/tags/fielderror.html
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/site/resources/tags/fielderror.html?rev=722198&r1=722197&r2=722198&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/site/resources/tags/fielderror.html (original)
+++ struts/struts2/trunk/core/src/site/resources/tags/fielderror.html Mon Dec  1 11:49:00
2008
@@ -82,6 +82,14 @@
 					<td align="left" valign="top">Set the html disabled attribute on rendered html
element</td>
 				</tr>
 				<tr>
+					<td align="left" valign="top">fieldName</td>
+					<td align="left" valign="top">false</td>
+					<td align="left" valign="top"></td>
+					<td align="left" valign="top">false</td>
+					<td align="left" valign="top">String</td>
+					<td align="left" valign="top">Field name for single field attribute usage</td>
+				</tr>
+				<tr>
 					<td align="left" valign="top">id</td>
 					<td align="left" valign="top">false</td>
 					<td align="left" valign="top"></td>

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java?rev=722198&r1=722197&r2=722198&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/FieldErrorTagTest.java
Mon Dec  1 11:49:00 2008
@@ -82,6 +82,17 @@
         verify(FieldErrorTagTest.class.getResource("fielderror-3.txt"));
     }
 
+     public void testWithFieldName() throws Exception {
+        FieldErrorTag tag = new FieldErrorTag();
+        tag.setFieldName("field1");
+        ((InternalAction)action).setHaveFieldErrors(true);
+        tag.setPageContext(pageContext);
+        tag.doStartTag();
+        tag.doEndTag();
+
+        verify(FieldErrorTagTest.class.getResource("fielderror-6.txt"));
+    }
+
     public void testWithParamsWithFieldErrors2() throws Exception {
         FieldErrorTag tag = new FieldErrorTag();
         ((InternalAction)action).setHaveFieldErrors(true);

Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/fielderror-6.txt
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/fielderror-6.txt?rev=722198&view=auto
==============================================================================
--- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/fielderror-6.txt
(added)
+++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/fielderror-6.txt
Mon Dec  1 11:49:00 2008
@@ -0,0 +1,3 @@
+<ul>
+	<li><span class="errorMessage">field error message number 1</span></li>
+</ul>
\ No newline at end of file



Mime
View raw message