Announcement Announcement Module
No announcement yet.
validations with MenuActionController Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • validations with MenuActionController

    I have the problem with validations.
    After submitting the form the following method is called in the sub class of MenuActionController. The following method creates createBinder to place null values within the fields where i didn't enter any data in the form.
    public ModelAndView saveNewDevice(HttpServletRequest request, 
            HttpServletResponse response) throws Exception { 
            List list1 = new ArrayList(); 
            List list2 = new ArrayList(); 
            Object command = newCommandObject(DeviceInstanceVO.class); 
          ServletRequestDataBinder binder = null; 
            binder =createBinder(request, command); 
            DeviceInstanceDaoJdbc dao = getDAO(); 
            String deviceTypeStr = request.getParameter("devType"); 
            Integer deviceTypeId = new Integer(deviceTypeStr); 
            list1 = dao.getCreatedDevice(); 
            list2 = dao.getSelectedDeviceTypes(deviceTypeId); 
            Map model = new HashMap(); 
            model.put("deviceData", list1); 
            model.put("deviceDataType", list2); 
            return new ModelAndView("device/SaveDevice", model); 
    the createBinder method replacing the empty fields or wrong data types (for example in the field time if i enter 'abcd') of the submitted form with null values.
    protected ServletRequestDataBinder createBinder(HttpServletRequest request, Object command) 
                      throws Exception { 
            ServletRequestDataBinder binder = null; 
            if (command instanceof DeviceInstanceVO) { 
               binder = new ServletRequestDataBinder(command, "command"); 
               binder.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, true)); 
            return binder; 
    But the problem is , instead of replacing with null values if i enter wrong data type (for example time ='abcd' ) then it should display some messagethat some message as data type is mismatched or related message.
    If i write validator class to check data type, how can i add to these methods to display the message without moving form to the next page.