当前位置: 首页>>代码示例>>Java>>正文


Java DataBinder.getBindingResult方法代码示例

本文整理汇总了Java中org.springframework.validation.DataBinder.getBindingResult方法的典型用法代码示例。如果您正苦于以下问题:Java DataBinder.getBindingResult方法的具体用法?Java DataBinder.getBindingResult怎么用?Java DataBinder.getBindingResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.validation.DataBinder的用法示例。


在下文中一共展示了DataBinder.getBindingResult方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBindTagWithIndexedPropertiesAndCustomEditor

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
public void testBindTagWithIndexedPropertiesAndCustomEditor() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	DataBinder binder = new ServletRequestDataBinder(tb, "tb");
	binder.registerCustomEditor(TestBean.class, null, new PropertyEditorSupport() {
		@Override
		public String getAsText() {
			return "something";
		}
	});
	Errors errors = binder.getBindingResult();
	errors.rejectValue("array[0]", "code1", "message1");
	errors.rejectValue("array[0]", "code2", "message2");
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb.array[0]");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", "array[0]".equals(status.getExpression()));
	// because of the custom editor getValue() should return a String
	assertTrue("Value is TestBean", status.getValue() instanceof String);
	assertTrue("Correct value", "something".equals(status.getValue()));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:27,代码来源:BindTagTests.java

示例2: testValidation

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void testValidation() throws BindException{
	
	Employee employee = new Employee();
	DataBinder binder = new DataBinder(employee);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.addPropertyValue("empId", "AA1000");
	pvs.addPropertyValue("empName", "Nobody");
	pvs.addPropertyValue("empAge", 10);
	binder.bind(pvs);
	
	Validator validator = new EmployeeValidator();
	Errors errors = binder.getBindingResult();
	validator.validate(employee, errors);
	
	assertFalse(errors.hasFieldErrors("empId"));
	assertFalse(errors.hasFieldErrors("empName"));
	assertTrue(errors.hasFieldErrors("empAge"));
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:20,代码来源:FormValidationTest.java

示例3: bindTagWithIndexedPropertiesAndCustomEditor

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Test
public void bindTagWithIndexedPropertiesAndCustomEditor() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	DataBinder binder = new ServletRequestDataBinder(tb, "tb");
	binder.registerCustomEditor(TestBean.class, null, new PropertyEditorSupport() {
		@Override
		public String getAsText() {
			return "something";
		}
	});
	Errors errors = binder.getBindingResult();
	errors.rejectValue("array[0]", "code1", "message1");
	errors.rejectValue("array[0]", "code2", "message2");
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb.array[0]");
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertTrue("Correct expression", "array[0]".equals(status.getExpression()));
	// because of the custom editor getValue() should return a String
	assertTrue("Value is TestBean", status.getValue() instanceof String);
	assertTrue("Correct value", "something".equals(status.getValue()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:BindTagTests.java

示例4: bind

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
private BindingResult bind(DataBinder binder, Object target, String values)
		throws Exception {
	Properties properties = PropertiesLoaderUtils
			.loadProperties(new ByteArrayResource(values.getBytes()));
	binder.bind(new MutablePropertyValues(properties));
	binder.validate();

	return binder.getBindingResult();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:RelaxedDataBinderTests.java

示例5: create

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
/**
 * Process the send form.
 */
@PostMapping
public ModelAndView create(final HttpServletRequest req,
                           final RedirectAttributes redirectAttributes)
    throws IOException, FileUploadException {

    if (!ServletFileUpload.isMultipartContent(req)) {
        throw new IllegalStateException("No multipart request!");
    }

    // Create encryptionKey and initialization vector (IV) to encrypt data
    final KeyIv encryptionKey = messageService.newEncryptionKey();

    // secret shared with receiver using the link - not stored in database
    final String linkSecret = messageService.newRandomId();

    final DataBinder binder = initBinder();

    final List<SecretFile> tmpFiles = handleStream(req, encryptionKey, binder);

    final EncryptMessageCommand command = (EncryptMessageCommand) binder.getTarget();
    final BindingResult errors = binder.getBindingResult();

    if (!errors.hasErrors()
        && command.getMessage() == null
        && (tmpFiles == null || tmpFiles.isEmpty())) {
        errors.reject(null, "Neither message nor files submitted");
    }

    if (errors.hasErrors()) {
        return new ModelAndView(FORM_SEND_MSG, binder.getBindingResult().getModel());
    }

    final String senderId = messageService.storeMessage(command.getMessage(), tmpFiles,
        encryptionKey, HashCode.fromString(linkSecret).asBytes(), command.getPassword(),
        Instant.now().plus(command.getExpirationDays(), ChronoUnit.DAYS));

    redirectAttributes
        .addFlashAttribute("messageSent", true)
        .addFlashAttribute("message", command.getMessage());

    return
        new ModelAndView("redirect:/send/" + senderId)
        .addObject("linkSecret", linkSecret);
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:48,代码来源:SendController.java

示例6: handleStream

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
private List<SecretFile> handleStream(final HttpServletRequest req,
                                      final KeyIv encryptionKey, final DataBinder binder)
    throws FileUploadException, IOException {

    final BindingResult errors = binder.getBindingResult();

    final MutablePropertyValues propertyValues = new MutablePropertyValues();
    final List<SecretFile> tmpFiles = new ArrayList<>();

    @SuppressWarnings("checkstyle:anoninnerlength")
    final AbstractMultipartVisitor visitor = new AbstractMultipartVisitor() {

        private OptionalInt expiration = OptionalInt.empty();

        @Override
        void emitField(final String name, final String value) {
            propertyValues.addPropertyValue(name, value);

            if ("expirationDays".equals(name)) {
                expiration = OptionalInt.of(Integer.parseInt(value));
            }
        }

        @Override
        void emitFile(final String fileName, final InputStream inStream) {
            final Integer expirationDays = expiration
                .orElseThrow(() -> new IllegalStateException("No expirationDays configured"));

            tmpFiles.add(messageService.encryptFile(fileName, inStream, encryptionKey,
                Instant.now().plus(expirationDays, ChronoUnit.DAYS)));
        }

    };

    try {
        visitor.processRequest(req);
        binder.bind(propertyValues);
        binder.validate();
    } catch (final IllegalStateException ise) {
        errors.reject(null, ise.getMessage());
    }

    return tmpFiles;
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:45,代码来源:SendController.java

示例7: validateEntity

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
@Override
public String validateEntity(T entity) {
    DataBinder binder = new DataBinder(entity);

    binder.setValidator(validator);

    binder.validate();

    BindingResult results = binder.getBindingResult();

    return prepareValidationErrorMessage(results, entity);
}
 
开发者ID:bullhorn,项目名称:starter-kit-spring-maven,代码行数:13,代码来源:AbstractDataTablesService.java

示例8: bind

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
/**
 * Bind the given request-data to the object. The object and
 * {@link BindingResult} is put to the model under the given name.
 *
 * @param request the HTTP-request.
 * @param model the model which contains the view-data.
 * @param object the object which should be changed.
 * @param objectName the name of the object in the model.
 * @return the result of the binding.
 */
public BindingResult bind(HttpServletRequest request, Model model,
        Object object, String objectName) {
    DataBinder binder = bindInternal(request, model, object, objectName);
    return binder.getBindingResult();

}
 
开发者ID:opensource21,项目名称:fuwesta,代码行数:17,代码来源:ServletBindingService.java

示例9: bindAndValidate

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
/**
 * Bind the given request-data to the object and validate is. The object and
 * {@link BindingResult} is put to the model under the given name.
 *
 * @param request the HTTP-request.
 * @param model the model which contains the view-data.
 * @param object the object which should be changed.
 * @param objectName the name of the object in the model.
 * @return the result of the binding and validation.
 */
public BindingResult bindAndValidate(HttpServletRequest request,
        Model model, Object object, String objectName) {
    DataBinder binder = bindInternal(request, model, object, objectName);
    binder.validate();
    return binder.getBindingResult();
}
 
开发者ID:opensource21,项目名称:fuwesta,代码行数:17,代码来源:ServletBindingService.java


注:本文中的org.springframework.validation.DataBinder.getBindingResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。