0

I have Bean DealSheetForm which has List of OrderDto beans as its property. OrderDtos has 4 datefields. I used @InitBinder to bind date format as MM/dd/yyyy at controller. Now I need to modify one of the date fields format to MM/dd/yyyy hh:mm:ss

I tried creating 2 CustomDateEditors in @InitBinder but that did not have any change on dateformat. If anyone has possible solution, please help me out.

Here is the DealSheetBean which contains OrdersDto Bean:

public class DealSheetForm {

    private CustomerDto customer=new CustomerDto();
    private AutoPopulatingList<OrdersDto> orders =new                            
               AutoPopulatingList<OrdersDto>(OrdersDto.class);      

    public AutoPopulatingList<OrdersDto> getOrders() {
      return orders;
    }

    public void setOrders(AutoPopulatingList<OrdersDto> orders) {
      this.orders = orders;
    }

    public CustomerDto getCustomer() {
        return customer;
    }

    public void setCustomer(CustomerDto customer) {
        this.customer = customer;
    }
}

Here is my Controller

@Controller
public class DealSheetController{

  @InitBinder
 public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat dateTimeFormat = new SimpleDateFormat("MM/dd/yyyy  
       HH:mm:ss");
     dateFormat.setLenient(false);
     dateTimeFormat.setLenient(false);

    binder.registerCustomEditor(Date.class,new CustomDateEditor(dateFormat, 
     true));
    binder.registerCustomEditor(Date.class,"orderDate",new  
    CustomDateEditor(dateTimeFormat, true));     
   }


   @RequestMapping(value="/agent/dealsheet.do",method=RequestMethod.POST)
   @ResponseBody
    public String saveDealSheets(@ModelAttribute("dealSheet") DealSheetForm  
     dealSheet,Map<String,Object> map,HttpServletRequest  
      request,HttpServletResponse response){
        try{                
            log.info("inside saveDealSheeeeeets()");
            Authentication 
            auth=SecurityContextHolder.getContext().getAuthentication();                
            String user=auth.getName();     
            HoveyUserDto userDto=this.userService.getUserByUsername(user);
            String agentNumber=userDto.getAgentNumber();
            this.dealSheetService.saveDealSheetToDB(dealSheet,agentNumber);
            String message="Orders Saved Successfully";
            map.put("message", message);
            return "success";
        }           
        catch(Exception e){
            log.error(e.getStackTrace().toString());                
            return "error";
        }       
    }   }
Jeevan Kumar
  • 43
  • 1
  • 1
  • 4

0 Answers0