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

  • Spring Validator and validation of a collection

    Hi,

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

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

    Code:
    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:

    Code:
    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(BeanWrapperImpl.java:540) at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:447) at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:424) at ...
    How do I tell the Validator the correct getter method?

    Tobias

    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, 06:55 AM. Reason: Solved
Working...
X