Results 1 to 2 of 2

Thread: Validating and collections

  1. #1
    Join Date
    May 2005
    Location
    London
    Posts
    9

    Question Validating and collections

    I'm trying to build a page that allows ther user to edit a number of records at once. I've done this by giving my backing object a collection of beans, each one of which is a simple bean.

    Most of this seems to work fine - I build the collection in the Controller's formBackingObject() method, and stuff it into the backing object. In my view (a JSP) I loop through the collection and show each bean as a row in a table. The spring:bind tag works fine here. When control is returned to the Controller's onSubmit() method, I can loop through the collection, and the beans have been updated with the user's input.

    So far, so good. The problem occurs when I try to add validation. Again, I can loop through the collection easily enough in the Validator, but should I find an error, I need to call errors.rejectValue(), and I don't know what to put into the first parameter. Where the field in error is a property of the backing object, you just pass its name, but in my case, the backing object's property is my collecttion, and it's a property of a member of the collection that I want to flag as being in error.

    Is there a way to make this work, or do I need another approach altogether?

  2. #2
    Join Date
    May 2005
    Location
    London
    Posts
    9

    Default

    Answering my own question - provided that I loop through the collection the old fasioned way, and so have the index number available to me, I can build a string like this:

    "myCollection[" + index + "].myBeanProperty"

    Seems to work fine!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •