Revision: 824
          http://stripes.svn.sourceforge.net/stripes/?rev=824&view=rev
Author:   bengunter
Date:     2008-01-31 17:35:06 -0800 (Thu, 31 Jan 2008)

Log Message:
-----------
Fixed STS-172. Added a new EL function hasErrors(ActionBean bean, String field) 
that can be used like
<c:if test="${s:hasErrors(actionBean, 'foo')}">...</c:if>

Modified Paths:
--------------
    trunk/stripes/resources/stripes.tld
    trunk/stripes/src/net/sourceforge/stripes/tag/ElFunctions.java

Modified: trunk/stripes/resources/stripes.tld
===================================================================
--- trunk/stripes/resources/stripes.tld 2008-02-01 00:46:36 UTC (rev 823)
+++ trunk/stripes/resources/stripes.tld 2008-02-01 01:35:06 UTC (rev 824)
@@ -2193,5 +2193,15 @@
         <name>enumName</name>
         
<function-class>net.sourceforge.stripes.tag.ElFunctions</function-class>
         <function-signature>java.lang.String 
name(java.lang.Enum)</function-signature>
+    </function>
+
+    <function>
+        <description>
+               Indicates if validation errors exist for the given field of the 
given ActionBean.
+               This allows for use of JSTL logic tags such as c:if and 
c:choose.
+        </description>
+        <name>hasErrors</name>
+        
<function-class>net.sourceforge.stripes.tag.ElFunctions</function-class>
+        <function-signature>boolean 
hasErrors(net.sourceforge.stripes.action.ActionBean, 
java.lang.String)</function-signature>
     </function>
 </taglib>

Modified: trunk/stripes/src/net/sourceforge/stripes/tag/ElFunctions.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/ElFunctions.java      
2008-02-01 00:46:36 UTC (rev 823)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/ElFunctions.java      
2008-02-01 01:35:06 UTC (rev 824)
@@ -14,6 +14,13 @@
  */
 package net.sourceforge.stripes.tag;
 
+import java.util.List;
+
+import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.action.ActionBeanContext;
+import net.sourceforge.stripes.validation.ValidationError;
+import net.sourceforge.stripes.validation.ValidationErrors;
+
 /**
  * A collection of static functions that are included in the Stripes tag 
library.  In most
  * cases these are not functions that are specific to Stripes, but simply 
functions that
@@ -28,4 +35,22 @@
     public static String name(Enum<?> e) {
         return e.name();
     }
+
+    /** Indicates if validation errors exist for the given field of the given 
[EMAIL PROTECTED] ActionBean}. */
+    public static boolean hasErrors(ActionBean actionBean, String field) {
+        if (actionBean == null || field == null)
+            return false;
+
+        ActionBeanContext context = actionBean.getContext();
+        if (context == null)
+            return false;
+
+        ValidationErrors errors = context.getValidationErrors();
+        if (errors == null || errors.isEmpty())
+            return false;
+
+        List<ValidationError> fieldErrors = errors.get(field);
+        return fieldErrors != null && fieldErrors.size() > 0;
+    }
+
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to