Example usage for org.springframework.validation BindingResult hasErrors

List of usage examples for org.springframework.validation BindingResult hasErrors

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult hasErrors.

Prototype

boolean hasErrors();

Source Link

Document

Return if there were any errors.

Usage

From source file:com.asual.summer.core.spring.ExtendedServletRequestDataBinder.java

public BindingResult getBindingResult() {
    BindingResult result = super.getInternalBindingResult();
    if ((RequestUtils.getRequest() != null && RequestUtils.isValidation()) && !result.hasErrors()) {
        result.addError(new ObjectError("validation", "success"));
    }//from ww  w  .j  a  va2 s  .com
    return result;
}

From source file:com.opencart.controller.CategoryController.java

@RequestMapping(value = "/category/add", method = RequestMethod.POST)
public ModelAndView categoryPost(@Valid @ModelAttribute Category category, BindingResult result,
        HttpServletRequest request, HttpServletResponse response) {
    if (result.hasErrors()) {
        return new ModelAndView("admin/addcategory");
    } else {/*from  www  . j a v a2s  . c o  m*/
        categoryService.add(category);
        String action = (String) request.getParameter("action");
        System.out.println("Action -->" + action);
        List<Category> categories = categoryService.list();
        ModelAndView mv = new ModelAndView("admin/category", "categories", categories);
        return mv;
    }
}

From source file:org.xinta.eazycode.components.shiro.web.controller.SecurityController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(Model model, @ModelAttribute LoginVO command, BindingResult errors) {

    loginValidator.validate(command, errors);

    if (errors.hasErrors()) {
        return showLoginForm(model, command);
    }/* w  ww .  j  a v a2 s  . c  o m*/

    UsernamePasswordToken token = new UsernamePasswordToken(command.getLoginName(), command.getPassword(),
            command.isRememberMe());
    try {
        SecurityUtils.getSubject().login(token);
    } catch (AuthenticationException e) {
        errors.reject("error.login.generic", "Invalid username or password.  Please try again.");
    }

    if (errors.hasErrors()) {
        return showLoginForm(model, command);
    } else {
        return "redirect:/home.do";
    }
}

From source file:com.izerui.user.UserSearchController.java

@RequestMapping("search")
public String search(@Valid UserSearchForm form, BindingResult result, @PageableDefaults Pageable pageable,
        Model model) {/*from  www .jav a  2s . co  m*/
    if (result.hasErrors()) {
        return "user/list";
    }

    String name = form.getName();
    String query = (StringUtils.hasText(name) ? name : "") + "%";
    Page<User> page = userService.findByNameLike(query, pageable);
    model.addAttribute("page", page);
    return "user/list";
}

From source file:net.przemkovv.sphinx.web.TaskController.java

@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public String updateTask(@PathVariable Long id, @Valid @ModelAttribute("task") Task task,
        BindingResult result) {
    task.setId(id);//from w w  w. jav a  2 s.  c o m
    if (result.hasErrors()) {
        return "view.tasks.edit";
    } else {
        taskService.saveTask(task);
        return "redirect:/tasks";
    }
}

From source file:org.busko.routemanager.web.admin.community.RouteSubmissionController.java

@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid RouteSubmission routeSubmission, BindingResult bindingResult, Model uiModel,
        HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, routeSubmission);
        return "admin/community/routesubmissions/create";
    }/* w w w .  j  av  a  2s . c  o  m*/
    uiModel.asMap().clear();

    routeSubmission.setSubmittedDateTime(new Date());
    routeSubmission.uploadFileData();
    routeSubmission.persist();
    return "redirect:/admin/community/routesubmissions/"
            + encodeUrlPathSegment(routeSubmission.getId().toString(), httpServletRequest);
}

From source file:pl.altkom.text.mvc.spring.controller.PersonController.java

@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@Valid Person person, BindingResult bindingResult) {

    System.out.println(person);/*from  w w w.j  av a 2 s  .c  o  m*/

    if (bindingResult.hasErrors()) {

        return "add";
    }
    personDAO.save(person);

    return "redirect:/home.htm";
}

From source file:com.test.springmvc.springmvcproject.IndexController.java

@RequestMapping(value = "register", method = RequestMethod.POST)
public String register(HttpSession session, ModelMap model, @Valid RegisterBean bean, BindingResult result) {

    if (!result.hasErrors()) {
        System.out.println("Pas d'erreurs !!");
        session.setAttribute("email_utilisateur", bean.getEmail());
        try {// w  w w  .  j a va 2s . com
            utilisateurService.create(bean);
        } catch (DuplicatedEntryException e) {
            result.addError(new FieldError("RegisterBean", "email", e.getMessage()));
            return "register";
        }
    } else {
        System.out.println("erreur presentes dans la validation : " + result.toString());
        return "register";
    }

    return "redirect:/index.do";
}

From source file:edu.ijse.tcd.controller.CustomerController.java

@RequestMapping(value = "addUpdateCustomer", method = RequestMethod.POST)
public String updateCustomer(@Valid Customer customer, BindingResult bindingResult, ModelMap map) {
    if (bindingResult.hasErrors()) {
        ArrayList<Customer> customers = customerService.getCustomers();
        map.addAttribute("customerList", customers);
        return "updateCustomer";
    }/*w ww  .  j  a v  a2 s .  c o  m*/
    customerService.updateCustomer(customer);
    ArrayList<Customer> customers = customerService.getCustomers();
    map.addAttribute("customerList", customers);
    map.addAttribute("customer", new Customer());
    return "customer";
}

From source file:gallery.web.validator.user.UserViewValidator.java

public BindingResult bindAndValidate(User command, HttpServletRequest request, User old_command) {
    BindingResult err = bindAndValidate(command, request);
    if (!err.hasErrors()) {
        if ((command.getPassword() == null && command.getPassword_repeat() != null)
                || (command.getPassword() != null
                        && !command.getPassword().equals(command.getPassword_repeat()))) {
            err.rejectValue("password_repeat", "password_repeat.different");
        }//from  ww w .  ja  v a  2s  . c o m
        if (old_command == null) {
            //creating new user (insert)
            if (userService.getRowCount("login", command.getLogin()) > 0) {
                err.rejectValue("login", "exists.login");
            }
            if (userService.getRowCount("email", command.getEmail()) > 0) {
                err.rejectValue("email", "exists.email");
            }
            if (!err.hasErrors()) {
                Set<Role> new_roles = new HashSet<Role>(1);
                new_roles.add(new Role("user", command));
                command.setRoles(new_roles);
            }
        } else {
            //user edits his private data (update)
            command.setId(old_command.getId());
            if (!command.getPassword_old().equals(old_command.getPassword())) {
                err.rejectValue("password_old", "password_old.different");
            }
            if (command.getPassword() == null || command.getPassword().equals("")) {
                command.setPassword(old_command.getPassword());
            }
            if ((!command.getLogin().equals(old_command.getLogin()))
                    && (userService.getRowCount("login", command.getLogin()) > 0)) {
                err.rejectValue("login", "exists.login");
            }
            if ((!command.getEmail().equals(old_command.getEmail()))
                    && (userService.getRowCount("email", command.getEmail()) > 0)) {
                err.rejectValue("email", "exists.email");
            }
            if (!err.hasErrors()) {
                command.setRoles(old_command.getRoles());
            }
        }
    }
    return err;
}