Example usage for org.springframework.validation DataBinder close

List of usage examples for org.springframework.validation DataBinder close

Introduction

In this page you can find the example usage for org.springframework.validation DataBinder close.

Prototype

public Map<?, ?> close() throws BindException 

Source Link

Document

Close this DataBinder, which may result in throwing a BindException if it encountered any errors.

Usage

From source file:cherry.foundation.type.format.CustomNumberFormatTest.java

private String parseAndPrint(String name, String value) throws BindException {
    Map<String, String> paramMap = new HashMap<>();
    paramMap.put(name, value);//from w w  w .  ja  va  2  s. c om

    Form form = new Form();
    DataBinder binder = new DataBinder(form, "target");
    binder.setConversionService(conversionService);
    binder.bind(new MutablePropertyValues(paramMap));

    BindingResult binding = BindingResultUtils.getBindingResult(binder.close(), "target");
    return (String) binding.getFieldValue(name);
}

From source file:org.agatom.springatom.cmp.wizards.core.CreateObjectWizardProcessor.java

/**
 * {@inheritDoc}//from   w  w w .ja va  2s.co  m
 */
@Override
@SuppressWarnings("UnusedAssignment")
public WizardResult onStepSubmit(final String step, final Map<String, Object> stepData, final Locale locale)
        throws Exception {
    LOGGER.debug(String.format("onStepSubmit(step=%s, stepData=%s)", step, stepData));

    final long startTime = System.nanoTime();
    final boolean isSubmitStep = StringUtils.hasText(step);

    if (LOGGER.isDebugEnabled() && isSubmitStep) {
        LOGGER.debug(String.format("step=%s therefore it is a step submit", step));
    }

    T contextObject = this.getContextObject();
    // Create appropriate binder.
    DataBinder binder = isSubmitStep ? this.createStepBinder(contextObject, step)
            : this.createGlobalBinder(contextObject);

    final ModelMap params = new ModelMap().addAllAttributes(stepData);
    final WizardResult finalResult = this.bind(binder, step, params, locale);

    if (!finalResult.hasErrors()) {
        LOGGER.debug(String.format("Bound to context object=%s without any error", contextObject));
        try {
            if (isSubmitStep) {
                final WizardResult localResult = this.submitStep(contextObject, params, step, locale);
                if (localResult != null) {
                    finalResult.merge(localResult);
                } else if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(String.format("%s does not execute any step submission", this.getWizardID()));
                }
            } else {
                finalResult.merge(this.submitWizard(contextObject, params, locale));
            }
        } catch (Exception submitExp) {
            LOGGER.error(String.format("Submission failed for contextObject=%s", contextObject), submitExp);
            finalResult.addError(submitExp);
            finalResult
                    .addFeedbackMessage(FeedbackMessage.newError().setMessage(submitExp.getLocalizedMessage()));
        } finally {
            binder.close();
        }
    }

    final long endTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(
                String.format("submitStep(step=%s, stepData=%s) executed in %d ms", step, stepData, endTime));
    }

    finalResult.addDebugData(WizardDebugDataKeys.TOTAL_TIME, endTime);
    finalResult.addDebugData(WizardDebugDataKeys.PROCESSOR, ClassUtils.getShortName(this.getClass()));
    finalResult.addDebugData(WizardDebugDataKeys.LOCALE, locale);

    // collect garbage
    binder = null;
    contextObject = null;
    System.gc();

    return finalResult;
}