Hi,

I'm not sure  if stripes has always worked this way or if something changed - 
and as always I could be doing something wrong.  If you have a List<X> in an 
action bean, and one of the fields in the list causes a validation error, the 
field name of the error is list.field, not list[N].field as I would expect.  
This prevents the one field from getting the "error" class.  Here's a simple 
example to demonstrate:

Domain class w/ string & integer

public class ModelObject {
      private String string;
      private Integer integer;

      public String getString() {
            return string;
      }
      public void setString(String string) {
            this.string = string;
      }

      public Integer getInteger() {
            return integer;
      }
      public void setInteger(Integer integer) {
            this.integer = integer;
      }
}

Simple Action bean with a list of those

public class IndexedValidationErrorAction extends
            SecureActionBean<User, ActionBeanContext> {

      private List<ModelObject> objects;


      @DefaultHandler
      public Resolution gotoIndexPage() {
            return new RedirectResolution("/");
      }


      public List<ModelObject> getObjects() {
            return objects;
      }
      public void setObjects(List<ModelObject> objects) {
            this.objects = objects;
      }
}

public class TestIndexedValidationErrors extends SecureTestFixture<User>{

      @Test
      public void testBody() throws Exception  {
            MockRoundtrip trip = 
createSecureTrip(IndexedValidationErrorAction.class);
            trip.addParameter("objects[0].string", "asdf");
            trip.addParameter("objects[0].integer", "123");
            trip.addParameter("objects[1].string", "asdfasdfasdf");
            trip.addParameter("objects[1].integer", "xxxx");
            trip.addParameter("objects[2].string", "asdasdfadfsasdfasdff");
            trip.addParameter("objects[2].integer", "nnn");
            trip.execute();
            printValidationErrors(trip);
      }

protected void printValidationErrors(MockRoundtrip trip) {
      StringBuffer sb = new StringBuffer(255);
            sb.append("\n\nValidation Errors:\n");
            for (Entry<String, List<ValidationError>> e : trip
                        .getValidationErrors().entrySet()) {
                  for (ValidationError ve : e.getValue()) {
                        sb.append(ve.getFieldName()).append('\t').append(
                                    ve.getFieldValue()).append('\n');
                  }
            }
            sb.append('\n');
            LOG.info(sb.toString());
      }
}


Results in

Validation Errors:
objects.integer   xxxx
objects.integer   nnn

Shouldn't that come back as
objects[1].integer      xxxx
objects[2].integer      nnn


Is that right?
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to