List of usage examples for org.springframework.validation DataBinder getObjectName
public String getObjectName()
From source file:org.agatom.springatom.cmp.wizards.core.AbstractWizardProcessor.java
private void doBind(final DataBinder binder, Map<String, Object> params) throws Exception { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format( "Binding allowed request parameters in %s to form object with name '%s', pre-bind formObject toString = %s", params, binder.getObjectName(), binder.getTarget())); if (binder.getAllowedFields() != null && binder.getAllowedFields().length > 0) { LOGGER.debug(/*from w ww . jav a 2s . com*/ String.format("(Allowed fields are %s)", StylerUtils.style(binder.getAllowedFields()))); } else { LOGGER.debug("(Any field is allowed)"); } } binder.bind(new MutablePropertyValues(params)); if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format( "Binding completed for form object with name '%s', post-bind formObject toString = %s", binder.getObjectName(), binder.getTarget())); LOGGER.debug(String.format("There are [%d] errors, details: %s", binder.getBindingResult().getErrorCount(), binder.getBindingResult().getAllErrors())); } }
From source file:org.gvnix.web.json.DataBinderDeserializer.java
/** * Deserializes JSON content into Map<String, String> format and then uses a * Spring {@link DataBinder} to bind the data from JSON message to JavaBean * objects./*from w ww . j a v a 2s . c o m*/ * <p/> * It is a workaround for issue * https://jira.springsource.org/browse/SPR-6731 that should be removed from * next gvNIX releases when that issue will be resolved. * * @param parser Parsed used for reading JSON content * @param ctxt Context that can be used to access information about this * deserialization activity. * * @return Deserializer value */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Object deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = parser.getCurrentToken(); MutablePropertyValues propertyValues = new MutablePropertyValues(); // Get target from DataBinder from local thread. If its a bean // collection // prepares array index for property names. Otherwise continue. DataBinder binder = (DataBinder) ThreadLocalUtil .getThreadVariable(BindingResult.MODEL_KEY_PREFIX.concat("JSON_DataBinder")); Object target = binder.getTarget(); // For DstaBinderList instances, contentTarget contains the final bean // for binding. DataBinderList is just a simple wrapper to deserialize // bean wrapper using DataBinder Object contentTarget = null; if (t == JsonToken.START_OBJECT) { String prefix = null; if (target instanceof DataBinderList) { prefix = binder.getObjectName().concat("[").concat(Integer.toString(((Collection) target).size())) .concat("]."); // BeanWrapperImpl cannot create new instances if generics // don't specify content class, so do it by hand contentTarget = BeanUtils.instantiateClass(((DataBinderList) target).getContentClass()); ((Collection) target).add(contentTarget); } else if (target instanceof Map) { // TODO LOGGER.warn("Map deserialization not implemented yet!"); } Map<String, String> obj = readObject(parser, ctxt, prefix); propertyValues.addPropertyValues(obj); } else { LOGGER.warn("Deserialization for non-object not implemented yet!"); return null; // TODO? } // bind to the target object binder.bind(propertyValues); // Note there is no need to validate the target object because // RequestResponseBodyMethodProcessor.resolveArgument() does it on top // of including BindingResult as Model attribute // For DAtaBinderList the contentTarget contains the final bean to // make the binding, so we must return it if (contentTarget != null) { return contentTarget; } return binder.getTarget(); }
From source file:no.abmu.questionnaire.webflow.MuseumStatisticFormAction.java
/** * Bind allowed parameters in the external context request parameter map to the form object using given binder. * @param context the action execution context, for accessing and setting data in "flow scope" or "request scope" * @param binder the data binder to use//w ww . j ava 2 s . c o m * @throws Exception when an unrecoverable exception occurs */ protected void doBind(RequestContext context, DataBinder binder) throws Exception { logger.debug("Execute local doBind"); if (logger.isDebugEnabled()) { logger.debug("Binding allowed request parameters in " + StylerUtils.style(context.getExternalContext().getRequestParameterMap()) + " to form object with name '" + binder.getObjectName() + "', pre-bind formObject toString = " + binder.getTarget()); if (binder.getAllowedFields() != null && binder.getAllowedFields().length > 0) { logger.debug("(Allowed fields are " + StylerUtils.style(binder.getAllowedFields()) + ")"); } else { logger.debug("(Any field is allowed)"); } } logger.debug("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBb"); logger.debug("BBBBBBBBB Value of binder befor binding BBBBBBBBBBBBBBBBBBb"); logger.debug("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBb"); logger.debug(binder); binder.bind(new MutablePropertyValues(context.getRequestParameters().asMap())); logger.debug("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBb"); logger.debug("BBBBBBBBB Value of binder after binding BBBBBBBBBBBBBBBBBBb"); logger.debug("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBb"); logger.debug(binder); if (logger.isDebugEnabled()) { logger.debug("Binding completed for form object with name '" + binder.getObjectName() + "', post-bind formObject toString = " + binder.getTarget()); logger.debug("There are [" + binder.getErrors().getErrorCount() + "] errors, details: " + binder.getErrors().getAllErrors()); } }