List of usage examples for org.springframework.validation BindException reject
@Override
public void reject(String errorCode, String defaultMessage)
From source file:com.jklas.sample.petclinic.web.AbstractClinicForm.java
/** * Method disallows duplicate form submission. Typically used to prevent * duplicate insertion of entities into the datastore. Shows a new form with * an error message./*from w w w .j a v a 2 s . com*/ */ protected ModelAndView disallowDuplicateFormSubmission(HttpServletRequest request, HttpServletResponse response) throws Exception { BindException errors = getErrorsForNewForm(request); errors.reject("duplicateFormSubmission", "Duplicate form submission"); return showForm(request, response, errors); }
From source file:it.geosolutions.geobatch.ui.mvc.FTPConfigFormController.java
@Override protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { FtpConfigDataBean givenData = (FtpConfigDataBean) command; if (givenData == null) { errors.reject("error.nullpointer", "Null data received"); } else {//from w ww. j av a2 s . co m /* VALIDATE ALL FIELDS */ if (request.getParameter("ssl") == null) { givenData.setSsl(false); } if (request.getParameter("autoStart") == null) { givenData.setAutoStart(false); } if (request.getParameter("anonEnabled") == null) { givenData.setAnonEnabled(false); } if (givenData.getMaxLogins() < 0) { errors.rejectValue("maxLogins", "error.code", "Ftp Max Logins must be greater than 0."); } if (givenData.getMaxLoginFailures() < 0) { errors.rejectValue("maxLoginFailures", "error.code", "Ftp Max Logins Failuers must be greater than 0."); } if (givenData.getLoginFailureDelay() < 0) { errors.rejectValue("loginFailureDelay", "error.code", "Ftp Login Failuers Delay must be greater than 0."); } } }
From source file:web.Controller.CloseacController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandCloseac, BindException errors) throws Exception { CommandBalanceCloseac command = (CommandBalanceCloseac) commandCloseac; Double somme;/*from w w w .j a v a 2 s . c o m*/ try { somme = closeacservice.closeAccount(command.getPassword()); return new ModelAndView("closeacsuccess", "somme", somme); } catch (AccountNONExistantException e) { errors.reject("Inexistant ACCOUNT", "This ACCOUNT doesn't exist"); return showForm(request, response, errors); } catch (WrongPasswordException e) { errors.reject("Authentification Failure", "wrong username or password"); return showForm(request, response, errors); } catch (DisabledUserProfileException e) { errors.reject("Disabled Profile", "Your Profile is Disabled this action is forbidden"); return showForm(request, response, errors); } }
From source file:org.apache.shiro.samples.spring.web.LoginController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object cmd, BindException errors) throws Exception { LoginCommand command = (LoginCommand) cmd; UsernamePasswordToken token = new UsernamePasswordToken(command.getUsername(), command.getPassword()); try {// ww w .j a v a2 s. co m SecurityUtils.getSubject().login(token); } catch (AuthenticationException e) { log.debug("Error authenticating.", e); errors.reject("error.invalidLogin", "The username or password was not correct."); } if (errors.hasErrors()) { return showForm(request, response, errors); } else { return new ModelAndView(getSuccessView()); } }
From source file:it.geosolutions.geobatch.ui.mvc.FTPUserFormController.java
@Override protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { FtpUserDataBean givenData = (FtpUserDataBean) command; if (givenData == null) { errors.reject("error.nullpointer", "Null data received"); } else {//from w ww .j a v a 2 s. co m /* VALIDATE ALL FIELDS */ if ((givenData.getUserName() == null) || (givenData.getUserName().trim().length() <= 0)) { errors.rejectValue("userName", "error.code", "Ftp User Name is mandatory."); } if ((givenData.getPassword() == null) || (givenData.getPassword().trim().length() <= 0)) { errors.rejectValue("password", "error.code", "Ftp User Password is mandatory."); } if ((givenData.getRepeatPassword() == null) || (givenData.getRepeatPassword().trim().length() <= 0)) { errors.rejectValue("repeatPassword", "error.code", "Ftp User Repeat Password is mandatory."); } if ((!givenData.getPassword().equals("")) && (!givenData.getRepeatPassword().equals(""))) { if (!givenData.getPassword().equals(givenData.getRepeatPassword())) { errors.rejectValue("password", "error.code", "The password must be the same."); } } if (request.getParameter("writePermission") == null) { givenData.setWritePermission(false); } if (!givenData.getDownloadRate().equals("")) { try { int downloadRate = Integer.parseInt(givenData.getDownloadRate()); if (downloadRate < 0) { errors.rejectValue("downloadRate", "error.code", "Ftp User Download Rate must be greater than 0."); } } catch (NumberFormatException e) { errors.rejectValue("downloadRate", "error.code", "Ftp User Download Rate must be an integer."); } } if (!givenData.getUploadRate().equals("")) { try { int uploadRate = Integer.parseInt(givenData.getUploadRate()); if (uploadRate < 0) { errors.rejectValue("uploadRate", "error.code", "Ftp User Upload Rate must be greater than 0."); } } catch (NumberFormatException e) { errors.rejectValue("uploadRate", "error.code", "Ftp User Upload Rate must be an integer."); } } } }
From source file:web.Controller.ConsultBalanceController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandBalance, BindException errors) throws Exception { CommandBalanceCloseac command = (CommandBalanceCloseac) commandBalance; Compte account;//from w w w .ja va2 s .c o m try { account = consultbalanceservice.getAccount(command.getAccountnumber(), command.getPassword()); return new ModelAndView("accountcreationsuccess", "compte", account); } catch (AccountNONExistantException e) { errors.reject("Inexistant ACCOUNT", "This ACCOUNT doesn't exist"); return showForm(request, response, errors); } catch (WrongPasswordException e) { errors.reject("Authentification Failure", "Wrong password"); return showForm(request, response, errors); } catch (DisabledUserProfileException e) { errors.reject("Disabled Profile", "Your Profile is Disabled this action is forbidden"); return showForm(request, response, errors); } }
From source file:web.Controller.DepositController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandWithdraw, BindException errors) throws Exception { CommandDepositWithdraw command = (CommandDepositWithdraw) commandWithdraw; Compte account;/*w w w .j a va 2s . c om*/ try { account = depositservice.depositinAccount(command.getAccountnumber(), command.getPassword(), command.getAmount()); return new ModelAndView("accountcreationsuccess", "compte", account); } catch (AccountNONExistantException e) { errors.reject("Inexistant ACCOUNT", "This ACCOUNT doesn't exist"); return showForm(request, response, errors); } catch (WrongPasswordException e) { errors.reject("Authentification Failure", "wrong password"); return showForm(request, response, errors); } catch (DisabledUserProfileException e) { errors.reject("Disabled Profile", "Your Profile is Disabled this action is forbidden"); return showForm(request, response, errors); } }
From source file:web.Controller.WithdrawController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandWithdraw, BindException errors) throws Exception { CommandDepositWithdraw command = (CommandDepositWithdraw) commandWithdraw; Compte account;/*w w w. j a va 2 s .c o m*/ try { account = withdrawservice.depositinAccount(command.getAccountnumber(), command.getPassword(), command.getAmount()); return new ModelAndView("accountcreationsuccess", "compte", account); } catch (DisabledUserProfileException e) { errors.reject("Disabled Profile", "Your Profile is Disabled this action is forbidden"); return showForm(request, response, errors); } catch (AccountNONExistantException e) { errors.reject("Inexistant ACCOUNT", "This ACCOUNT doesn't exist"); return showForm(request, response, errors); } catch (WrongPasswordException e) { errors.reject("Authentification Failure", "wrong username or password"); return showForm(request, response, errors); } catch (InsufficientBalanceException e) { errors.reject("Insufficient Balance", "Your Balance is Insufficient"); return showForm(request, response, errors); } }
From source file:web.Controller.AddAccountController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandAddAccount, BindException errors) throws Exception { CommandAddAccount command = (CommandAddAccount) commandAddAccount; Compte compte = new Compte(); compte.setDateOuverture(new Date()); try {/*from w w w .j a v a 2s . com*/ compte.setSolde(Double.parseDouble(command.getSolde())); addaccountservice.addAccount(compte, command.getPass()); return new ModelAndView("accountcreationsuccess", "compte", compte); } catch (DisabledUserProfileException e) { errors.reject("Disabled Profile", "Your Profile is Disabled this action is forbidden"); return showForm(request, response, errors); } catch (WrongPasswordException e) { errors.reject("Wrong Password", "Your Password is Wrong"); return showForm(request, response, errors); } catch (java.lang.NumberFormatException e) { errors.reject("NumberFormatException", "amount is invalid"); return showForm(request, response, errors); } }
From source file:web.Controller.TransferController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object commandTransfer, BindException errors) throws Exception { CommandTransfer command = (CommandTransfer) commandTransfer; HashMap<String, Object> accounts; try {/*from ww w. jav a 2s. co m*/ accounts = (HashMap<String, Object>) transferservice.transfertoAccount(command.getAccountnumber(), command.getPassword(), command.getTargetaccountnumber(), command.getAmount()); return new ModelAndView("transferinfo", accounts); } catch (DifferentAccountException e) { errors.reject("Different ACCOUNT", "This ACCOUNT is not yours!"); return showForm(request, response, errors); } catch (AccountNONExistantException e) { errors.reject("Inexistant ACCOUNT", "This ACCOUNT of yours doesn't exist"); return showForm(request, response, errors); } catch (WrongPasswordException e) { errors.reject("Authentification Failure", "wrong username or password"); return showForm(request, response, errors); } catch (TargetAccountNONExistantException e) { errors.reject("Inexistant Target Account", "Target ACCOUNT doesn't exist"); return showForm(request, response, errors); } catch (InsufficientBalanceException e) { errors.reject("Insufficient Balance", "Your Balance is Insufficient"); return showForm(request, response, errors); } catch (DisabledUserProfileException e) { errors.reject("Disabled Profile", "Your Profile is Disabled this action is forbidden"); return showForm(request, response, errors); } }