Results 1 to 5 of 5

Thread: MultiActionController + registerCustomEditor

  1. #1
    Join Date
    Aug 2006
    Posts
    24

    Default MultiActionController + registerCustomEditor

    Hi, I have difficulty adding registerCustomEditor to MultiActionController.
    I need some help.

    here is my code:

    public ModelAndView test(HttpServletRequest request, HttpServletResponse response, Object command) throws Exception
    {
    ServletRequestDataBinder binder = (ServletRequestDataBinder)request.getAttribute("BI NDER");
    BindException errors = new BindException(binder.getBindingResult());

    ModelAndView mav = new ModelAndView("test");
    mav.addObject(errors.getAllErrors());
    mav.addObject("content",getContent());

    return mav;
    }

    and

    @Override
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception
    {

    logger.debug("------------------------------------------- initBinder");

    binder.registerCustomEditor(Currency.class, new PatternedNumberEditor(Currency.class));
    request.setAttribute("BINDER", binder);
    super.initBinder(request, binder);
    }

    but when my page is upload, I see the instance (com.Currency@e7fda0) and not the object, i.e. the editor is not used but I have also this message on my server:

    <Must create new command of class [java.lang.Object]>
    <Binding request parameters onto MultiActionController command>


    however before creating the object, the method initBinder is running.

    Someone can make a suggestion ?

  2. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by mhadjis View Post
    Code:
    ModelAndView mav = new ModelAndView("test");
    mav.addObject(errors.getAllErrors());
    I have not looked into it but try to change the above to

    Code:
    ModelAndView mav = new ModelAndView("test", errors.getModel());
    From what I remember your approach is the way to go in general.

    (And please use [ CODE][ /CODE] tags.)

    Joerg
    This post can contain insufficient information.

  3. #3

    Default not sure what I am missing in initBinder + multiactionController.

    hi

    I am having a similar problem . Not sure what I am missing.

    I have a multiactioncontroller

    Code:
    @Override
    	public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception{
    		
    		
    	
    		
    		super.initBinder(request, binder);
    		
    	
    		
    		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    		sdf.setLenient(false);
    		
    		CustomDateEditor editor = new CustomDateEditor(sdf,false);
    		
    		binder.registerCustomEditor(Date.class,
    				editor);
    		binder.registerCustomEditor(Date.class, 
    				editor);
    		
    		
    	}
    and in my JSP i am using this.

    Code:
    <form:input path="dynamicPollUrlList[${pRow.index}].publishStartTime" size="20" cssErrorClass="errors" />
    I am getting the date. But its not in the format as i desired ( MM/dd/yyyy )
    What I see is the complete date ( Fri Sep 26 17:41:11 PDT 2008 )

    Any idea what I am missing ?

  4. #4

    Default

    anybody.
    I have tried many things , but nothing is working.

    I even tried removing the initBinder() and put this code in the handellerMethod.
    But still no good.

    Code:
    ServletRequestDataBinder binder = new ServletRequestDataBinder(pollUrlsList);
    
    		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    		sdf.setLenient(false);
    		
    		CustomDateEditor editor = new CustomDateEditor(sdf,false);
    		
    		binder.registerCustomEditor(Date.class,"dynamicPollUrlList[0].publishStartTime",
    				editor);
    		
    		binder.bind(request);

  5. #5
    Join Date
    Sep 2008
    Posts
    2

    Default

    Quote Originally Posted by tdhaayushverma View Post
    anybody.
    I have tried many things , but nothing is working.

    I even tried removing the initBinder() and put this code in the handellerMethod.
    But still no good.

    Code:
    ServletRequestDataBinder binder = new ServletRequestDataBinder(pollUrlsList);
    
    		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    		sdf.setLenient(false);
    		
    		CustomDateEditor editor = new CustomDateEditor(sdf,false);
    		
    		binder.registerCustomEditor(Date.class,"dynamicPollUrlList[0].publishStartTime",
    				editor);
    		
    		binder.bind(request);
    It is helped me to solve the problem.

    Thanks.
    With best regards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •