當前位置: 首頁>>代碼示例>>Java>>正文


Java WebDataBinder類代碼示例

本文整理匯總了Java中org.springframework.web.bind.WebDataBinder的典型用法代碼示例。如果您正苦於以下問題:Java WebDataBinder類的具體用法?Java WebDataBinder怎麽用?Java WebDataBinder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebDataBinder類屬於org.springframework.web.bind包,在下文中一共展示了WebDataBinder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@InitBinder("employeeForm")
public void initBinder(WebDataBinder binder){
	binder.setValidator(employeeValidator);
	
	binder.registerCustomEditor(Date.class, new DateEditor());
	binder.registerCustomEditor(Integer.class, "age", new AgeEditor());
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:8,代碼來源:FormController.java

示例2: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.registerCustomEditor(SignatureForm.class, new EnumPropertyEditor(SignatureForm.class));
	binder.registerCustomEditor(ASiCContainerType.class, new EnumPropertyEditor(ASiCContainerType.class));
	binder.registerCustomEditor(SignaturePackaging.class, new EnumPropertyEditor(SignaturePackaging.class));
	binder.registerCustomEditor(SignatureLevel.class, new EnumPropertyEditor(SignatureLevel.class));
	binder.registerCustomEditor(DigestAlgorithm.class, new EnumPropertyEditor(DigestAlgorithm.class));
	binder.registerCustomEditor(EncryptionAlgorithm.class, new EnumPropertyEditor(EncryptionAlgorithm.class));
}
 
開發者ID:esig,項目名稱:dss-demonstrations,代碼行數:10,代碼來源:SignatureController.java

示例3: updateBindingResult

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
/**
 * Add {@link BindingResult} attributes to the model for attributes that require it.
 */
private void updateBindingResult(NativeWebRequest request, ModelMap model) throws Exception {
	List<String> keyNames = new ArrayList<String>(model.keySet());
	for (String name : keyNames) {
		Object value = model.get(name);

		if (isBindingCandidate(name, value)) {
			String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + name;

			if (!model.containsAttribute(bindingResultKey)) {
				WebDataBinder dataBinder = binderFactory.createBinder(request, value, name);
				model.put(bindingResultKey, dataBinder.getBindingResult());
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:ModelFactory.java

示例4: resolveCookieValue

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
private Object resolveCookieValue(String cookieName, boolean required, String defaultValue,
		MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
		throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (cookieName.length() == 0) {
		cookieName = getRequiredParameterName(methodParam);
	}
	Object cookieValue = resolveCookieValue(cookieName, paramType, webRequest);
	if (cookieValue == null) {
		if (defaultValue != null) {
			cookieValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingCookieException(cookieName, paramType);
		}
		cookieValue = checkValue(cookieName, cookieValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, cookieName);
	initBinder(handlerForInitBinderCall, cookieName, binder, webRequest);
	return binder.convertIfNecessary(cookieValue, paramType, methodParam);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:HandlerMethodInvoker.java

示例5: resolveModelAttribute

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
private WebDataBinder resolveModelAttribute(String attrName, MethodParameter methodParam,
		ExtendedModelMap implicitModel, NativeWebRequest webRequest, Object handler) throws Exception {

	// Bind request parameter onto object...
	String name = attrName;
	if ("".equals(name)) {
		name = Conventions.getVariableNameForParameter(methodParam);
	}
	Class<?> paramType = methodParam.getParameterType();
	Object bindObject;
	if (implicitModel.containsKey(name)) {
		bindObject = implicitModel.get(name);
	}
	else if (this.methodResolver.isSessionAttribute(name, paramType)) {
		bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
		if (bindObject == null) {
			raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
		}
	}
	else {
		bindObject = BeanUtils.instantiateClass(paramType);
	}
	WebDataBinder binder = createBinder(webRequest, bindObject, name);
	initBinder(handler, name, binder, webRequest);
	return binder;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:HandlerMethodInvoker.java

示例6: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@Override
public void initBinder(WebDataBinder binder, WebRequest request) {
	binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
	if (this.directFieldAccess) {
		binder.initDirectFieldAccess();
	}
	if (this.messageCodesResolver != null) {
		binder.setMessageCodesResolver(this.messageCodesResolver);
	}
	if (this.bindingErrorProcessor != null) {
		binder.setBindingErrorProcessor(this.bindingErrorProcessor);
	}
	if (this.validator != null && binder.getTarget() != null &&
			this.validator.supports(binder.getTarget().getClass())) {
		binder.setValidator(this.validator);
	}
	if (this.conversionService != null) {
		binder.setConversionService(this.conversionService);
	}
	if (this.propertyEditorRegistrars != null) {
		for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
			propertyEditorRegistrar.registerCustomEditors(binder);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:ConfigurableWebBindingInitializer.java

示例7: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.setAutoGrowNestedPaths(false);
	binder.registerCustomEditor(
			Long.class,
			new CustomNumberEditor(Long.class, true));
	binder.registerCustomEditor(
			Double.class,
			new CustomNumberEditor(Double.class, true));
	binder.registerCustomEditor(
			BigDecimal.class,
			new CustomNumberEditor(
					BigDecimal.class,
					new DecimalFormat("#,##0.00"),
					true));
	binder.registerCustomEditor(
			Boolean.class,
			new CustomBooleanEditor(true));
	binder.registerCustomEditor(
			Date.class,
			new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true));
	binder.registerCustomEditor(
			Object.class,
			new ObjectTypeEditorHelper());
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:26,代碼來源:ExpedientConsultaInformeController.java

示例8: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.registerCustomEditor(
			Long.class,
			new CustomNumberEditor(Long.class, true));
	binder.registerCustomEditor(
			Double.class,
			new CustomNumberEditor(Double.class, true));
	binder.registerCustomEditor(
			BigDecimal.class,
			new CustomNumberEditor(
					BigDecimal.class,
					new DecimalFormat("#,##0.00"),
					true));
	binder.registerCustomEditor(
			Boolean.class,
			new CustomBooleanEditor(true));
	binder.registerCustomEditor(
			Date.class,
			new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true));
	binder.registerCustomEditor(
			Object.class,
			new ObjectTypeEditorHelper());
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:25,代碼來源:ExpedientDocumentController.java

示例9: updateModelSessionAttributesSaved

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@Test
public void updateModelSessionAttributesSaved() throws Exception {
	String attributeName = "sessionAttr";
	String attribute = "value";
	ModelAndViewContainer container = new ModelAndViewContainer();
	container.addAttribute(attributeName, attribute);

	WebDataBinder dataBinder = new WebDataBinder(attribute, attributeName);
	WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
	given(binderFactory.createBinder(this.webRequest, attribute, attributeName)).willReturn(dataBinder);

	ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.sessionAttrsHandler);
	modelFactory.updateModel(this.webRequest, container);

	assertEquals(attribute, container.getModel().get(attributeName));
	assertEquals(attribute, this.sessionAttributeStore.retrieveAttribute(this.webRequest, attributeName));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ModelFactoryTests.java

示例10: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.registerCustomEditor(
			Long.class,
			new CustomNumberEditor(Long.class, true));
	binder.registerCustomEditor(
			Double.class,
			new CustomNumberEditor(Double.class, true));
	binder.registerCustomEditor(
			BigDecimal.class,
			new CustomNumberEditor(
					BigDecimal.class,
					new DecimalFormat("#,##0.00"),
					true));
	binder.registerCustomEditor(
			Boolean.class,
			new CustomBooleanEditor(false));
	binder.registerCustomEditor(
			Date.class,
			new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true));
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:22,代碼來源:ExpedientIniciarPasFormController.java

示例11: updateBindingResult

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
/**
 * Add {@link BindingResult} attributes to the model for attributes that require it.
 */
private void updateBindingResult(NativeWebRequest request, ModelMap model) throws Exception {
	List<String> keyNames = new ArrayList<String>(model.keySet());
	for (String name : keyNames) {
		Object value = model.get(name);

		if (isBindingCandidate(name, value)) {
			String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + name;

			if (!model.containsAttribute(bindingResultKey)) {
				WebDataBinder dataBinder = dataBinderFactory.createBinder(request, value, name);
				model.put(bindingResultKey, dataBinder.getBindingResult());
			}
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:ModelFactory.java

示例12: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.registerCustomEditor(SignatureForm.class, new EnumPropertyEditor(SignatureForm.class));
	binder.registerCustomEditor(ASiCContainerType.class, new EnumPropertyEditor(ASiCContainerType.class));
	binder.registerCustomEditor(SignatureLevel.class, new EnumPropertyEditor(SignatureLevel.class));
	binder.registerCustomEditor(DigestAlgorithm.class, new EnumPropertyEditor(DigestAlgorithm.class));
	binder.registerCustomEditor(EncryptionAlgorithm.class, new EnumPropertyEditor(EncryptionAlgorithm.class));
}
 
開發者ID:esig,項目名稱:dss-demonstrations,代碼行數:9,代碼來源:SignatureMultipleDocumentsController.java

示例13: initBinder

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
@InitBinder
public void initBinder(WebDataBinder binder) {
	binder.registerCustomEditor(ASiCContainerType.class, new EnumPropertyEditor(ASiCContainerType.class));
	binder.registerCustomEditor(SignatureForm.class, new EnumPropertyEditor(SignatureForm.class));
	binder.registerCustomEditor(SignaturePackaging.class, new EnumPropertyEditor(SignaturePackaging.class));
	binder.registerCustomEditor(SignatureLevel.class, new EnumPropertyEditor(SignatureLevel.class));
}
 
開發者ID:esig,項目名稱:dss-demonstrations,代碼行數:8,代碼來源:ExtensionController.java

示例14: resolveArgument

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
/**
 * Resolve the argument from the model or if not found instantiate it with
 * its default if it is available. The model attribute is then populated
 * with request values via data binding and optionally validated
 * if {@code @java.validation.Valid} is present on the argument.
 * @throws BindException if data binding and validation result in an error
 * and the next method parameter is not of type {@link Errors}.
 * @throws Exception if WebDataBinder initialization fails.
 */
@Override
public final Object resolveArgument(
		MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest request, WebDataBinderFactory binderFactory)
		throws Exception {

	String name = ModelFactory.getNameForParameter(parameter);
	Object attribute = (mavContainer.containsAttribute(name)) ?
			mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, request);

	WebDataBinder binder = binderFactory.createBinder(request, attribute, name);
	if (binder.getTarget() != null) {
		bindRequestParameters(binder, request);
		validateIfApplicable(binder, parameter);
		if (binder.getBindingResult().hasErrors()) {
			if (isBindExceptionRequired(binder, parameter)) {
				throw new BindException(binder.getBindingResult());
			}
		}
	}

	// Add resolved attribute and BindingResult at the end of the model

	Map<String, Object> bindingResultModel = binder.getBindingResult().getModel();
	mavContainer.removeAttributes(bindingResultModel);
	mavContainer.addAllAttributes(bindingResultModel);

	return binder.getTarget();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:39,代碼來源:ModelAttributeMethodProcessor.java

示例15: validateIfApplicable

import org.springframework.web.bind.WebDataBinder; //導入依賴的package包/類
/**
 * Validate the model attribute if applicable.
 * <p>The default implementation checks for {@code @javax.validation.Valid}.
 * @param binder the DataBinder to be used
 * @param parameter the method parameter
 */
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
	Annotation[] annotations = parameter.getParameterAnnotations();
	for (Annotation annot : annotations) {
		if (annot.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = AnnotationUtils.getValue(annot);
			binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
			break;
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:ModelAttributeMethodProcessor.java


注:本文中的org.springframework.web.bind.WebDataBinder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。