Revision: 299
Author:   tfenne
Date:     2006-04-26 04:46:02 -0700 (Wed, 26 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/stripes/?rev=299&view=rev

Log Message:
-----------
Fix for STS-180: required field validation does not work for <stripes:file> 
uploads.  Now it checks that a filename was supplied and that the file was 
greater than 0 bytes in length.

Modified Paths:
--------------
    
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
      2006-04-23 11:39:34 UTC (rev 298)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
      2006-04-26 11:46:02 UTC (rev 299)
@@ -598,6 +598,7 @@
         }
 
         Map<String,Validate> validationInfos = 
this.validations.get(bean.getClass());
+        StripesRequestWrapper req = 
StripesRequestWrapper.findStripesWrapper(bean.getContext().getRequest());
 
         if (validationInfos != null) {
             boolean wizard = bean.getClass().getAnnotation(Wizard.class) != 
null;
@@ -617,7 +618,7 @@
                     if (!wizard || fieldsOnPage.contains(propertyName)) {
                         String[] values = 
bean.getContext().getRequest().getParameterValues(propertyName);
                         log.debug("Checking required field: ", propertyName, 
", with values: ", values);
-                        checkSingleRequiredField(propertyName, propertyName, 
values, errors);
+                        checkSingleRequiredField(propertyName, propertyName, 
values, req, errors);
                     }
                 }
             }
@@ -652,7 +653,7 @@
                         if (validationInfo != null && validationInfo.required()
                                 && applies(validationInfo, bean.getContext())) 
{
                             checkSingleRequiredField
-                                    (name.getName(), name.getStrippedName(), 
values, errors);
+                                    (name.getName(), name.getStrippedName(), 
values, req, errors);
                         }
                     }
                 }
@@ -685,8 +686,20 @@
     protected void checkSingleRequiredField(String name,
                                             String strippedName,
                                             String[] values,
+                                            StripesRequestWrapper req,
                                             ValidationErrors errors) {
-        if (values == null || values.length == 0) {
+
+        // Firstly if the post is a multipart request, check to see if a file 
was
+        // sent under that parameter name
+        FileBean file = null;
+        if (req.isMultipart() && (file = req.getFileParameterValue(name)) != 
null) {
+            if (file.getSize() <= 0) {
+                errors.add(name, new 
ScopedLocalizableError("validation.required",
+                                                            
"valueNotPresent"));
+            }
+        }
+        // And if not, see if any regular parameters were sent
+        else if (values == null || values.length == 0) {
             ValidationError error = new 
ScopedLocalizableError("validation.required",
                                                                
"valueNotPresent");
             error.setFieldValue(null);


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



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to