Announcement Announcement Module
No announcement yet.
Spring Validator and validation of a collection Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Validator and validation of a collection


    Is there a possibility to validate a collection? I have the following:

    class Video {
    List<AudioTrack> tracks;
    How can I validate each item of the audiotrack list? I tried this

    class VideoValidator implements Validator
      public void validate(Object obj, Errors errors) {
    	Video video = (Video) obj;
            for(int i = 0; i < video.getAudioTracks().size(); i++) {
                   if(video.getAudioTracks().get(i).getLanguage() == null)
    			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "audioTracks[" + i + "].language", "LANGUAGE_MISSING", "Audio language is missing");
    because the form field is rendered with the name "audioTracks[x].language"

    But I get this exception:

    org.springframework.beans.NotReadablePropertyException: Invalid property 'audiotracks[0]' of bean class [lu.bce.movie2me.web.model.Main]: Bean property 'audiotracks[0]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? at org.springframework.beans.BeanWrapperImpl.getPropertyValue( at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper( at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath( at ...
    How do I tell the Validator the correct getter method?


    EDIT: The approach was the right way but looking at the error message it is obvious that there was a typo error - so mea culpa, forget about it... I should have cleaned my tmp dir, sorry
    Last edited by tobimat80; Sep 12th, 2010, 05:55 AM. Reason: Solved