Skip to main content

Posts

Showing posts with the label Spring Framework

Overview of Spring Framework

Spring framework is the platform which supports for developing java applications using its infrastructure (Physical and organizational structures). Spring allows you to develop application with simple plan old java objects (POJO). Spring takes care of managing objects and their lifecycle. This framework provides the stage for your objects to play their role and all dependencies the objects depend on are provided at that time whenever required. Spring framework integrates your objects to create an application and make them independent from each other. Spring connects all objects being maintained by it by injecting their reference in each other as per requirements. Spring able to manage various common requirements for your application like database connection, transactions, emailing, orm, aop etc. For example, if you imagine a calculator application which has the following objects to accomplish its functionality: Keyboards Display Adder Subs tractor Divider Mult...

javax.validation.ConstraintViolationException: validation failed for classes [*] during update time for groups [javax.validation.groups.Default, ]

This message wasted many hours to figure out the solution. javax.validation.ConstraintViolationException: validation failed for classes [*] during update time for groups [javax.validation.groups.Default, ] When I applied the validation as following, I found that the confirmPassword is the field causing validation error. ValidatorFactory factory = Validation.buildDefaultValidatorFactory();         Validator validator = factory.getValidator();                 Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);         System.out.println("constraintViolations.size : "+constraintViolations.size());         Iterator<ConstraintViolation<User>> iterator = constraintViolations.iterator();         while (iterator.hasNext()) {       ...

Code Snippet- Redirection in Spring MVC

    @ RequestMapping ( value  =   "/admin" )      public   String   openDashboard ()   {          return   "redirect:/admin/admin-home" ;      }     @ RequestMapping ( value  =   "/admin/admin-home" )      public   String   adminHome ()   {          return   "dpgsource/admin-dashboard" ;      }     

Spring MVC - Ajax based form processing using JQuery and JSON with server side validation

Spring MVC provides support for processing the form as well as server side validation. It maps request parameters to form backing bean and validate the bean object if we have used @Valid annotation. When we submit the form, form get displayed with the error messages if validation is failed. Error messages are managed by Spring MVC and spring MVC binds them to the input fields. But, If we want to submit the form using ajax request, form page will not refresh and spring MVC cannot send validation error messages to browsers. In this case, server side validation does not work as per my expectations. So here I devised my approach to use the spring MVC validation even in ajax based form submission.  I am using JQuery to serialize the form data and capturing them in controller. In controller, form data is being mapped in User bean and User bean is validated based on field validation annotations. Now if validation is get failed and some errors are appeared there, I collect them in Use...