本文整理了Java中org.springframework.validation.BindException.hasErrors()
方法的一些代码示例,展示了BindException.hasErrors()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BindException.hasErrors()
方法的具体详情如下:
包路径:org.springframework.validation.BindException
类名称:BindException
方法名:hasErrors
暂无
代码示例来源:origin: openmrs/openmrs-core
@Test
public void shouldFailIfGivenNull() {
validator.validate(null, errors);
Assert.assertTrue(errors.hasErrors());
Assert.assertEquals("error.general", errors.getAllErrors().get(0).getCode());
}
代码示例来源:origin: openmrs/openmrs-core
@Test
public void validate_shouldPassValidationIfAllRequiredValuesAreSet() {
attributeType.setName("name");
attributeType.setMinOccurs(1);
attributeType.setDatatypeClassname(RegexValidatedTextDatatype.class.getName());
attributeType.setDatatypeConfig("[a-z]+");
validator.validate(attributeType, errors);
Assert.assertFalse(errors.hasErrors());
}
}
代码示例来源:origin: openmrs/openmrs-core
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
attributeType.setName("name");
attributeType.setMinOccurs(1);
attributeType.setDatatypeClassname(RegexValidatedTextDatatype.class.getName());
attributeType.setDatatypeConfig("[a-z]+");
attributeType.setHandlerConfig("HandlerConfig");
validator.validate(attributeType, errors);
Assert.assertFalse(errors.hasErrors());
}
代码示例来源:origin: openmrs/openmrs-core
/**
* @see org.openmrs.api.FormService#saveForm(org.openmrs.Form)
*/
@Override
public Form saveForm(Form form) throws APIException {
checkIfFormsAreLocked();
BindException errors = new BindException(form, "form");
formValidator.validate(form, errors);
if (errors.hasErrors()) {
throw new APIException(errors);
}
if (form.getFormFields() != null) {
for (FormField ff : form.getFormFields()) {
if (ff.getForm() == null) {
ff.setForm(form);
} else if (!ff.getForm().equals(form)) {
throw new APIException("Form.contains.FormField.error", new Object[] { ff });
}
}
}
return dao.saveForm(form);
}
代码示例来源:origin: openmrs/openmrs-core
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
ProgramWorkflowService pws = Context.getProgramWorkflowService();
Patient patient = Context.getPatientService().getPatient(6);
PatientProgram pp = new PatientProgram();
pp.setPatient(patient);
pp.setProgram(pws.getProgram(1));
pp.setDateEnrolled(new Date());
pp.setVoidReason("voidReason");
BindException errors = new BindException(pp, "program");
new PatientProgramValidator().validate(pp, errors);
Assert.assertEquals(false, errors.hasErrors());
}
代码示例来源:origin: org.springframework/org.springframework.web.portlet
/**
* Validate all pages and process finish.
* If there are page validation errors, show the corresponding view page.
* @see #validatePagesAndFinish
*/
private ModelAndView renderValidatePagesAndFinish(
RenderRequest request, RenderResponse response, Object command, BindException errors, int currentPage)
throws Exception {
// In case of any errors -> show current page.
if (errors.hasErrors())
return showPage(request, errors, currentPage);
// No remaining errors -> proceed with finish.
return renderFinish(request, response, command, errors);
}
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@RequestMapping(value="/containers/{containerName:.+}/definitions/{definitionName:.+}/new", method=RequestMethod.POST)
public String saveInstanceDefinition(Model model, HttpServletRequest request, @PathVariable String containerName, @PathVariable String definitionName) {
ContainerManager cm = serviceManagerHelper.findContainerManagerByContainerName(containerName);
ServiceDeployment sd = retrieveServiceDeployment(request);
ServiceDefinition serviceDefinition = getServiceDefinition(definitionName, cm);
BindException errors = new BindException(sd, MODEL_SERVICE_DEPLOYMENT);
new ServiceDeploymentValidator(serviceDefinition, !StringUtils.equals(request.getParameter("type"), SERVICE_DEPLOYMENT_TYPE_FORM)).validate(sd, errors);
if (errors.hasErrors()) {
Object targetServiceDeployment = transformServiceDeployment(sd, request.getParameter("type"));
fillModel(model, targetServiceDeployment, sd.getServiceId(), serviceDefinition, containerName, MODEL_OPERATION_TYPE_NEW);
model.addAttribute(BindingResult.MODEL_KEY_PREFIX + MODEL_SERVICE_DEPLOYMENT, errors);
return "console.platform.container.definition.new." + request.getParameter("type");
}
DeploymentResult deployResult = cm.deployNewService(sd);
model.addAttribute("deployResults", Collections.singletonMap(sd.getServiceId(), deployResult));
model.addAttribute("backUrl", "/containers/" + containerName + "/services");
return "console.platform.services.redeploy.results";
}
代码示例来源:origin: org.springframework/org.springframework.web.portlet
/**
* This implementation calls <code>showForm</code> in case of errors,
* and delegates to <code>onSubmitRender<code>'s full version else.
* <p>This can only be overridden to check for an action that should be executed
* without respect to binding errors, like a cancel action. To just handle successful
* submissions without binding errors, override one of the <code>onSubmitRender</code>
* methods.
* @see #showForm(RenderRequest, RenderResponse, BindException)
* @see #onSubmitRender(RenderRequest, RenderResponse, Object, BindException)
* @see #onSubmitRender(Object, BindException)
* @see #onSubmitRender(Object)
* @see #processFormSubmission(ActionRequest, ActionResponse, Object, BindException)
*/
@Override
protected ModelAndView renderFormSubmission(RenderRequest request, RenderResponse response, Object command, BindException errors)
throws Exception {
if (errors.hasErrors() || isFormChangeRequest(request)) {
return showForm(request, response, errors);
}
else {
return onSubmitRender(request, response, command, errors);
}
}
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@RequestMapping(value="/containers/{containerName:.+}/services/{serviceId:.+}/edit", method=RequestMethod.POST)
public String editServicePropertiesComplete(Model model, HttpServletRequest request, @PathVariable String containerName, @PathVariable String serviceId) {
ContainerManager cm = serviceManagerHelper.findContainerManagerByContainerName(containerName);
ServiceDeployment sd = retrieveServiceDeployment(request);
ServiceDefinition serviceDefinition = getServiceDefinition(sd.getServiceDefinitionId(), cm);
BindException errors = new BindException(sd, MODEL_SERVICE_DEPLOYMENT);
new ServiceDeploymentValidator(serviceDefinition, !StringUtils.equals(request.getParameter("type"), SERVICE_DEPLOYMENT_TYPE_FORM)).validate(sd, errors);
if (errors.hasErrors()) {
Object targetServiceDeployment = transformServiceDeployment(sd, request.getParameter("type"));
fillModel(model, targetServiceDeployment, sd.getServiceId(), serviceDefinition, containerName, MODEL_OPERATION_TYPE_NEW);
model.addAttribute(BindingResult.MODEL_KEY_PREFIX + MODEL_SERVICE_DEPLOYMENT, errors);
return "console.platform.container.definition.new." + request.getParameter("type");
}
DeploymentResult deployResult;
if (cm.undeployService(sd.getServiceId())) {
deployResult = cm.deployNewService(sd);
} else {
deployResult = new DeploymentResult("Error while undeploying service");
}
model.addAttribute("deployResults", Collections.singletonMap(sd.getServiceId(), deployResult));
model.addAttribute("backUrl", "/containers/" + containerName + "/services");
return "console.platform.services.redeploy.results";
}
代码示例来源:origin: springframework/spring-web
/**
* Treats errors as fatal. Use this method only if
* it's an error if the input isn't valid.
* This might be appropriate if all input is from dropdowns, for example.
* @throws ServletRequestBindingException subclass of ServletException on any binding problem
*/
public void closeNoCatch() throws ServletRequestBindingException {
if (getErrors().hasErrors()) {
throw new ServletRequestBindingException(
"Errors binding onto object '" + getErrors().getObjectName() + "'", getErrors());
}
}
代码示例来源:origin: org.springframework/spring-webflow
/**
* Bind incoming request parameters to allowed fields of the form object.
* <p>
* NOTE: This action method is not designed to be overidden and might become <code>final</code> in a future
* version of Spring Web Flow. If you need to execute custom data binding logic have your flow call this method
* along with your own custom methods as part of a single action chain. Alternatively, override the
* {@link #doBind(RequestContext, DataBinder)} hook.
* @param context the action execution context, for accessing and setting data in "flow scope" or "request scope"
* @return "success" if there are no binding errors, "error" otherwise
* @throws Exception an <b>unrecoverable</b> exception occured, either checked or unchecked
*/
public Event bind(RequestContext context) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Executing bind");
}
Object formObject = getFormObject(context);
DataBinder binder = createBinder(context, formObject);
doBind(context, binder);
putFormErrors(context, binder.getErrors());
return binder.getErrors().hasErrors() ? error() : success();
}
代码示例来源:origin: org.springframework/spring-webflow
return binder.getErrors().hasErrors() ? error() : success();
代码示例来源:origin: org.springframework/org.springframework.web.portlet
if (!errors.hasErrors() || (this.allowDirtyBack && targetPage < currentPage) ||
(this.allowDirtyForward && targetPage > currentPage)) {
代码示例来源:origin: org.sakaiproject.metaobj/sakai-metaobj-tool-lib
if (errors.hasErrors()) {
logger.debug("Form submission errors: " + errors.getErrorCount());
HttpServletHelper.getInstance().reloadApplicationMap(request, application);
代码示例来源:origin: org.springframework/org.springframework.web.portlet
throws Exception {
if (errors.hasErrors()) {
if (logger.isDebugEnabled()) {
logger.debug("Data binding errors: " + errors.getErrorCount());
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
if (errors.hasErrors()) {
result = showForm(request, response, errors, errors.getModel());
代码示例来源:origin: org.springframework/org.springframework.web.portlet
/**
* Validate all pages and process finish.
* If there are page validation errors, show the corresponding view page.
* @see #renderValidatePagesAndFinish
*/
private void validatePagesAndFinish(
ActionRequest request, ActionResponse response, Object command, BindException errors, int currentPage)
throws Exception {
// In case of binding errors -> show current page.
if (errors.hasErrors()) {
setPageRenderParameter(response, currentPage);
passRenderParameters(request, response);
return;
}
if (!suppressValidation(request)) {
// In case of remaining errors on a page -> show the page.
for (int page = 0; page < getPageCount(request, command); page++) {
validatePage(command, errors, page, true);
if (errors.hasErrors()) {
setPageRenderParameter(response, currentPage);
passRenderParameters(request, response);
return;
}
}
}
// No remaining errors -> proceed with finish.
if (!isRedirectAction())
setPageRenderParameter(response, currentPage);
processFinish(request, response, command, errors);
}
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
if (errors.hasErrors()) {
result = showForm(request, response, errors, errors.getModel());
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
if (errors.hasErrors()) {
result = showForm(request, response, errors, errors.getModel());
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
if (errors.hasErrors()) {
result = showForm(request, response, errors, errors.getModel());
内容来源于网络,如有侵权,请联系作者删除!