Example usage for org.springframework.validation BindingResult toString

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.frat.common.validation.ValidateException.java

@Override
public String getMessage() {
    final StringBuilder sb = new StringBuilder("bindingResults string:");
    for (BindingResult bindingResult : bindingResults) {
        sb.append(bindingResult.toString()).append(",");
    }//ww  w .  j  a v  a2 s  .c om
    return sb.toString();
}

From source file:io.hedwig.petclinic.ui.web.PetController.java

@RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.POST)
public String processCreationForm(@Valid Pet pet, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        System.out.println("PET in if");
        System.out.println("PET " + result.toString());
        return "pets/petForm";
    } else {/*from   w ww  .  jav a 2s. co  m*/
        System.out.println("PET in else");
        this.clinicService.savePet(pet);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}

From source file:com.cme.hr.controller.FamilyMemberController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
public ModelAndView createNewFamilyMember(@ModelAttribute FamilyMember familyMember, BindingResult result,
        final RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (result.hasErrors()) {
        System.out.println("soy el error " + result.toString());
        ModelAndView mav = new ModelAndView("familyMember-new", "familyMember", familyMember);
        initSelect(mav);//w w w. j a  v  a  2  s .c o m
        return mav;
    }

    ModelAndView mav = new ModelAndView();
    String message = "New familyMember was successfully created.";
    redirectAttributes.addFlashAttribute("message", message);

    familyMemberService.create(familyMember);
    Integer p = familyMember.getIdPerson();
    HttpSession session = request.getSession(true);
    session.setAttribute("id_Person", p);

    mav.setViewName("redirect:/familyMember/list/{idPerson}.html");

    return mav;
}

From source file:fr.univrouen.poste.web.SignUpController.java

@RequestMapping(method = RequestMethod.POST)
public String create(UserRegistrationForm userRegistration, BindingResult result, Model model,
        HttpServletRequest request) {/*  w  ww  .  j  av  a 2  s  . c om*/
    if (AppliConfig.getCacheCandidatCanSignup()) {
        // be sure that there is no password sent by the web form
        userRegistration.setPassword(null);
        if (result.hasErrors()) {
            log.error(result.toString());
            return createForm(model);
        } else {
            if (User.countFindUsersByEmailAddress(userRegistration.getEmailAddress()) > 0) {
                model.addAttribute("errorMessage",
                        "Un compte avec cette mme adresse mail est dj prsent dans cette application !");
                return createForm(model);
            } else {
                createUserService.createCandidatUser(userRegistration);
                return "signup/thanks";
            }
        }
    } else {
        return "redirect:/";
    }
}

From source file:com.cme.hr.controller.PersonController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
public ModelAndView createNewPerson(@ModelAttribute Person person, BindingResult result,
        final RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (result.hasErrors()) {
        System.out.println("soy el error " + result.toString());
        ModelAndView mav = new ModelAndView("person-new", "person", person);
        initSelect(mav);/*ww w.  ja v a  2  s.  c  o  m*/
        return mav;
    }

    personService.create(person);
    Integer p = person.getIdPerson();
    HttpSession session = request.getSession(true);
    session.setAttribute("id_Person", p);

    ModelAndView mav = new ModelAndView("redirect:/background/create.html");

    return mav;
}

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 {/*from   w w w  .java 2 s  .c  om*/
            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:cs544.videohouse.controller.VideoController.java

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String checkUploadVideo(@Validated Video video, BindingResult result,
        final RedirectAttributes redirectAttributes) {
    String view = "upload";
    String videoExt = FilenameUtils.getExtension(video.getFile().getOriginalFilename());
    System.out.println("extension : " + videoExt);
    video.setType(videoExt);//w ww  .j a  v  a2  s.  c om
    String imageExt = FilenameUtils.getExtension(video.getImage().getOriginalFilename());
    System.out.println("extension : " + videoExt);
    video.setType(videoExt);
    video.setImageType(imageExt);
    video.setDate(Utility.getCurrentDate());
    System.out.println(result.toString());
    if (result.hasErrors()) {
        //  return new ModelAndView("upload", "command", video);
        return view;
    } else {
        videoService.uploadVideo(video);
        redirectAttributes.addFlashAttribute("successMessage",
                video.getTitle() + " video successfully uploaded.");
        // save file;
        System.out.println("save");
        view = "redirect:/upload" + "#" + video.getTitle() + "#" + video.getId();
        return view;
    }
}

From source file:org.jasig.portlet.announcements.controller.AdminTopicController.java

/**
 * Saves the Topic that was submitted//  w w  w. j a  v a 2s  .c o  m
 * @param topic
 * @param result
 * @param status
 * @param request
 * @param response
 * @throws PortletException
 */
@RequestMapping(params = "action=addTopic")
public void actionAddTopicForm(@ModelAttribute("topic") Topic topic, BindingResult result, SessionStatus status,
        ActionRequest request, ActionResponse response) throws PortletException {

    if (!UserPermissionChecker.isPortalAdmin(request)) {
        throw new UnauthorizedException("You do not have access to create a topic");
    }

    new TopicValidator().validate(topic, result);
    if (result.hasErrors()) {
        if (log.isDebugEnabled())
            log.debug("Error in form: " + result.toString());
        response.setRenderParameter("action", "addTopic");
        return;
    }

    if (!result.hasErrors() && topic != null) {
        if (log.isDebugEnabled())
            log.debug("No errors in form");

        // no id has been assigned by hibernate, so this must be a new topic
        if (!topic.hasId()) {
            topic.setCreator(request.getRemoteUser());
        } else {
            Long id = topic.getId();
            Topic oldTopic = announcementService.getTopic(id);

            topic.setCreator(oldTopic.getCreator());
            topic.setAdmins(oldTopic.getAdmins());
            topic.setAudience(oldTopic.getAudience());
            topic.setModerators(oldTopic.getModerators());
            topic.setAuthors(oldTopic.getAuthors());
        }
        announcementService.addOrSaveTopic(topic);
        status.setComplete();

        response.setRenderParameter("action", "baseAdmin");
    }

}

From source file:au.org.ala.biocache.web.OccurrenceController.java

@RequestMapping(value = "/occurrences/index/download*", method = RequestMethod.GET)
public String occurrenceIndexDownload(@Valid DownloadRequestParams requestParams, BindingResult result,
        @RequestParam(value = "apiKey", required = false) String apiKey,
        @RequestParam(value = "ip", required = false) String ip, Model model, HttpServletResponse response,
        HttpServletRequest request) throws Exception {

    if (result.hasErrors()) {
        logger.info("validation failed  " + result.getErrorCount() + " checks");
        logger.debug(result.toString());
        model.addAttribute("errorMessage", getValidationErrorMessage(result));
        //response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
        return VALIDATION_ERROR;//result.toString();
    }/*from   www . j  av  a2  s . com*/

    ip = ip == null ? getIPAddress(request) : ip;
    ServletOutputStream out = response.getOutputStream();
    //search params must have a query or formatted query for the download to work
    if (requestParams.getQ().isEmpty() && requestParams.getFormattedQuery().isEmpty()) {
        return null;
    }
    if (apiKey != null) {
        occurrenceSensitiveDownload(requestParams, apiKey, ip, true, response, request);
        return null;
    }
    try {
        downloadService.writeQueryToStream(requestParams, response, ip, out, false, true);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}

From source file:au.org.ala.biocache.web.OccurrenceController.java

@RequestMapping(value = "/occurrences/download/batchFile", method = RequestMethod.GET)
public String batchDownload(HttpServletRequest request, @Valid final DownloadRequestParams params,
        BindingResult result, @RequestParam(value = "file", required = true) String filepath,
        @RequestParam(value = "directory", required = true, defaultValue = "/data/biocache-exports") final String directory,
        @RequestParam(value = "ip", required = false) String ip, Model model) throws Exception {

    if (result.hasErrors()) {
        logger.info("validation failed  " + result.getErrorCount() + " checks");
        logger.debug(result.toString());
        model.addAttribute("errorMessage", getValidationErrorMessage(result));
        //response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
        return VALIDATION_ERROR;//result.toString();
    }/*  w ww .  j a  v a2  s. c o  m*/

    final File file = new File(filepath);

    final SpeciesLookupService mySpeciesLookupService = this.speciesLookupService;
    ip = ip == null ? getIPAddress(request) : ip;
    final DownloadDetailsDTO dd = downloadService.registerDownload(params, ip, DownloadType.RECORDS_INDEX);

    if (file.exists()) {
        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    //start a thread
                    CSVReader reader = new CSVReader(new FileReader(file));
                    String[] row = reader.readNext();
                    while (row != null) {

                        //get an lsid for the name
                        String lsid = mySpeciesLookupService.getGuidForName(row[0]);
                        if (lsid != null) {
                            try {
                                //download records for this row
                                String outputFilePath = directory + File.separatorChar
                                        + row[0].replace(" ", "_") + ".txt";
                                String citationFilePath = directory + File.separatorChar
                                        + row[0].replace(" ", "_") + "_citations.txt";
                                logger.debug(
                                        "Outputting results to:" + outputFilePath + ", with LSID: " + lsid);
                                FileOutputStream output = new FileOutputStream(outputFilePath);
                                params.setQ("lsid:\"" + lsid + "\"");
                                Map<String, Integer> uidStats = searchDAO.writeResultsFromIndexToStream(params,
                                        output, false, dd, false);
                                FileOutputStream citationOutput = new FileOutputStream(citationFilePath);
                                downloadService.getCitations(uidStats, citationOutput, params.getSep(),
                                        params.getEsc());
                                citationOutput.flush();
                                citationOutput.close();
                                output.flush();
                                output.close();
                            } catch (Exception e) {
                                logger.error(e.getMessage(), e);
                            }
                        } else {
                            logger.error("Unable to match name: " + row[0]);
                        }
                        row = reader.readNext();
                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                } finally {
                    downloadService.unregisterDownload(dd);
                }
            }
        };
        t.start();
    }
    return null;
}