spring - @initbinder not getting invoked for few parameters -


i'm working on spring application , using @initbinder in controller form submission. working first 2 parameters remaining propertyeditors not getting invoked.

initbinder

@initbinder     public void initbinder(webdatabinder binder) {         simpledateformat sdf = new simpledateformat("dd/mm/yyyy");         sdf.setlenient(true);         binder.registercustomeditor(date.class, new customdateeditor(sdf, true));         binder.registercustomeditor(systemrole.class, new systemroleeditor(systemroledao));          /* below editors not called */          binder.registercustomeditor(designation.class,new designationeditor(designationdao));         binder.registercustomeditor(domain.class, new domaineditor(domaindao));         binder.registercustomeditor(employeetype.class, new employeetypeeditor(employeetypedao));         binder.registercustomeditor(grade.class,new gradeeditor(gradedao));         binder.registercustomeditor(teamrole.class, new teamroleeditor(teamroledao));         binder.registercustomeditor(status.class, new statuseditor());         logger.info("in init binder");     } 

controller method called on form submission

@requestmapping(value="/employee/new", method = requestmethod.post)     @responsebody     public string create(@modelattribute("user") @validated user user, //@modelattribute("info") @validated userinfo info,               bindingresult result, webrequest request, errors errors) {         string password = "tcs@1234";          try{             logger.info(request.getparameter("info.grade"));             logger.info(request.getparameter("grade"));             userinfo info = user.getinfo();             info.setuser(user);                                  user.setpassword((new bcryptpasswordencoder()).encode(password));             logger.info(user);             logger.info(info);             //employeeservice.add(user);                         return "true";         }         catch(exception exception){             exception.printstacktrace();             return "error";         }      } 

model hierarchy: (only attributes concerned in questions)

  • user
  • systemrole
  • userinfo(info object in controller method)
    • date
    • designation
    • domain
    • grade
    • team role
    • status
    • employeetype

propertyeditor: (each of working , non-working )
non-working:

@component public class gradeeditor extends propertyeditorsupport{     @autowired     private igradedao gradedao;     private final log logger = logfactory.getlog(getclass());     private string format;     public gradeeditor(igradedao gradedao) {         this.gradedao = gradedao;     }      public void setformat(string format) {         this.format = format;     }      public void setastext(string text) {         if (format != null && format.equals("uppercase")) {             text = text.touppercase();         }         grade grade = this.gradedao.get(integer.parseint(text));         logger.info(text);         logger.info(grade);         if(grade == null){             grade = new grade();             grade.setname(text);         }         setvalue(grade);     }  } 

working

@component public class systemroleeditor extends propertyeditorsupport{     @autowired     private isystemroledao systemroledao;     private final log logger = logfactory.getlog(getclass());     private string format;        public systemroleeditor(isystemroledao systemroledao){         this.systemroledao = systemroledao;     }     public void setformat(string format) {         this.format = format;     }      public void setastext(string text) {         logger.info(text);         if (format != null && format.equals("uppercase")) {             text = text.touppercase();         }                 systemrole systemrole = systemroledao.get(integer.parseint(text));         setvalue(systemrole);     } } 


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -