Announcement Announcement Module
Collapse
No announcement yet.
Spring global data binding Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring global data binding

    Hi, I'm using Spring 3.1.1 and Spring MVC 3.1.1 and I'm trying to do global data binding.

    I have a custom date binder in my controller that uses the following code:


    Code:
    @InitBinder
    private void dateBinder(WebDataBinder binder) {
    // The date format to parse or output your dates SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); // Create a new CustomDateEditor CustomDateEditor editor = new CustomDateEditor(dateFormat, true); // Register it as custom editor for the Date type binder.registerCustomEditor(Date.class, editor);
    }
    This is working fine, however I'm trying to apply this globally, to do that, I created a class

    Code:
    public class ClinicBindingInitializer implements WebBindingInitializer {
    @Override public void initBinder(WebDataBinder binder, WebRequest arg1) {
    [INDENT=2]SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); // Create a new CustomDateEditor CustomDateEditor editor = new CustomDateEditor(dateFormat, true); binder.registerCustomEditor(Date.class, editor);[/INDENT]
    }
    }
    and adding the following configuration in my servlet-context.xml

    Code:
    <beans:bean class="org.springframework.web.servlet.mvc.annotation.An notationMethodHandlerAdapter">
    <beans: property name="cacheSeconds" value="0" /> <beans: property name="webBindingInitializer" ref="webBindingInitializer"/>
    </beans:bean> <beans:bean id="webBindingInitializer" class="br.com.appus.hub.infrastructure.web.ClinicBinding Initializer"></beans:bean>
    and removing the init bind in the controller. However it doesn't work. I checked some places and it seems like it is correct. Is there anything else that I should do?
    Last edited by Migore; Jun 4th, 2014, 09:09 AM.

  • #2
    This question is probably a better candidate for StackOverflow, perhaps with the "spring" and "spring-mvc" tags.

    Could you post your question there?
    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment

    Working...
    X