2011-12-08 34 views
1

我已经从jsf弹出来了,我在这里是新的,,,我想为我的IdField类有一个转换器,,,我做了一些研究并写了我自己的属性编辑器,,,弹簧属性编辑器不起作用

public class IdFieldPropertyEditor extends PropertyEditorSupport { 

,我在调度-servlet.xml中注册它

<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> 
    <property name="customEditors"> 
     <map> 
      <entry key="com.example.IdField"> 
       <bean class="com.example.IdFieldPropertyEditor" /> 
      </entry> 
     </map> 
    </property> 
</bean> 

所以,我了解这些步骤是不够的,但我仍然得到一个错误,如大炮从字符串转换到IdField ,,,

can a nyone有助于了解我错过了哪些步骤?谢谢,,,

回答

3

CustomEditorConfigurer与Spring MVC无关,它配置属性编辑器解释XML配置文件中的值。

要为特定控制器配置属性编辑器,请使用@InitBinder -annotated方法。要为所有控制器全局执行此操作,请使用自定义WebBindingInitializer。见15.3.2.12 Customizing WebDataBinder initialization

+0

或者使用@ControllerAdvice注释建议控制器http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-controller-advice – Sllouyssgort