2011-12-27 35 views
2

當我讀到這裏:春天StringTrimmerEditor一個不工作

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/portlet.html#portlet-ann-webdatabinder

正如我在其他一些問題見過像this one,我註冊StringTrimmerEditor一個在我的控制器是這樣的:

@Controller 
public class MyController{ 


    @InitBinder 
    public void initBinder(WebDataBinder binder) 
    { 
     binder.registerCustomEditor(StringTrimmerEditor.class,new StringTrimmerEditor(false)); 
    } 

它編譯並運行,但不起作用,它不修剪數據。我不知道我錯過了什麼。任何人?

感謝

回答

6

javadoc救援:

公共無效registerCustomEditor(類requiredType, 屬性編輯器屬性編輯器)

Description copied from interface: PropertyEditorRegistry 
Register the given custom property editor for all properties of the given type. 

Specified by: 
    registerCustomEditor in interface PropertyEditorRegistry 

Parameters: 
    requiredType - the type of the property 
    propertyEditor - the editor to register 

類不應該是類編輯器它應該是您希望編輯器應用的字段的類型:String.class

+0

我不得不承認昨天晚上我很懶惰,所以不是在研究我而是在這裏問了一下,期待今天早上有答案。 – de3 2011-12-28 14:57:36