2011-11-09 49 views
2

由於包括<mvc:annotation-driven/>在將多選列表框的選擇綁定到命令bean上的相應列表屬性時遇到了問題。在引入<mvc:annotation-driven/>之前,它工作正常。<mvc:annotation-driven />並綁定到集合

我有一個自定義集合編輯器:

@InitBinder 
public void initBinder(WebDataBinder binder) { 
    binder.registerCustomEditor(List.class, new CustomCollectionEditor(List.class) { 
     protected Object convertElement(Object element) {   
     String fieldName = (String)element; 

     for (Field field : fields) { 
      if (field.getFieldName().equals(fieldName)) 
       return field; 
     } 

     return element; 
     } 
    }); 
} 

這在以前將導致表單控制器接收List<Field>代表列表中選擇。但是,自從使用<mvc:annotation-driven/>我現在得到的是List<List<Field>>

任何人都可以幫助闡明這種行爲嗎?

回答

0

這可能不是差得遠,但...

如果你創建自己的AnnotationMethodHandlerAdapter設置自定義webBindingInitializer上它,你需要有<mvc:annotation-driven />AnnotationMethodHandlerAdapter後,否則<mvc:annotation-driver />創建一個會在使用中並且您的自定義聯編程序將不會被使用。

嘗試移動它,如果它還沒有最後。

除此之外,我只能建議在你的活頁夾內設置一個斷點來查看它是否被調用。

+0

謝謝!這很有用!我在''下面添加了'AnnotationMethodHandlerAdapter',將它們交換完畢,現在所有的工作都很棒! – Stuart

+0

我很高興它的工作:) 通常順序是不是在春季配置導入,所以當它有點兒你。 –