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


Java ServletRequestDataBinder.bind方法代碼示例

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


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

示例1: bind

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
private void bind(ServletRequest request, ServletRequestDataBinder dataBinder) {
    MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
    MultipartRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartRequest.class);
    if (multipartRequest != null) {
        bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
    }

    String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
    Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
    if (uriVars != null) {
        for (Map.Entry<String, String> entry : uriVars.entrySet()) {
            if (mpvs.contains(entry.getKey())) {
                logger.warn("Skipping URI variable '" + entry.getKey()
                        + "' since the request contains a bind value with the same name.");
            } else {
                mpvs.addPropertyValue(entry.getKey(), entry.getValue());
            }
        }
    }

    this.extendDataBinder.doExtendBind(mpvs, dataBinder);

    dataBinder.bind(mpvs);
}
 
開發者ID:superhj1987,項目名稱:spring-mvc-model-attribute-alias,代碼行數:25,代碼來源:SuishenServletModelAttributeMethodProcessor.java

示例2: getErrorsForNewForm

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * Create a BindException instance for a new form.
 * Called by {@link #showNewForm}.
 * <p>Can be used directly when intending to show a new form but with
 * special errors registered on it (for example, on invalid submit).
 * Usually, the resulting BindException will be passed to
 * {@link #showForm(HttpServletRequest, HttpServletResponse, BindException)},
 * after registering the errors on it.
 * @param request current HTTP request
 * @return the BindException instance
 * @throws Exception in case of an invalid new form object
 * @see #showNewForm
 * @see #showForm(HttpServletRequest, HttpServletResponse, BindException)
 * @see #handleInvalidSubmit
 */
protected final BindException getErrorsForNewForm(HttpServletRequest request) throws Exception {
	// Create form-backing object for new form.
	Object command = formBackingObject(request);
	if (command == null) {
		throw new ServletException("Form object returned by formBackingObject() must not be null");
	}
	if (!checkCommand(command)) {
		throw new ServletException("Form object returned by formBackingObject() must match commandClass");
	}
	
	// Bind without validation, to allow for prepopulating a form, and for
	// convenient error evaluation in views (on both first attempt and resubmit).
	ServletRequestDataBinder binder = createBinder(request, command);
	BindException errors = new BindException(binder.getBindingResult());
	if (isBindOnNewForm()) {
		logger.debug("Binding to new form");
		binder.bind(request);
		onBindOnNewForm(request, command, errors);
	}
	
	// Return BindException object that resulted from binding.
	return errors;
}
 
開發者ID:openmrs,項目名稱:openmrs-module-legacyui,代碼行數:39,代碼來源:AbstractFormController.java

示例3: bindAndValidate

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * Bind the parameters of the given request to the given command object.
 * @param request current HTTP request
 * @param command the command to bind onto
 * @return the ServletRequestDataBinder instance for additional custom validation
 * @throws Exception in case of invalid state or arguments
 */
protected final ServletRequestDataBinder bindAndValidate(HttpServletRequest request, Object command) throws Exception {
	
	ServletRequestDataBinder binder = createBinder(request, command);
	BindException errors = new BindException(binder.getBindingResult());
	if (!suppressBinding(request)) {
		binder.bind(request);
		onBind(request, command, errors);
		if (this.validators != null && isValidateOnBinding() && !suppressValidation(request, command, errors)) {
			for (int i = 0; i < this.validators.length; i++) {
				ValidationUtils.invokeValidator(this.validators[i], command, errors);
			}
		}
		onBindAndValidate(request, command, errors);
	}
	return binder;
}
 
開發者ID:openmrs,項目名稱:openmrs-module-legacyui,代碼行數:24,代碼來源:BaseCommandController.java

示例4: exportHandler

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
public ModelAndView exportHandler(HttpServletRequest request, HttpServletResponse resp) throws Exception {
  	getLog().info("ExportHandler()");
  	ExportCommand command = new ExportCommand();
  	command.setContext(onecmdb);
  	
  	ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
binder.bind(request);
	
  	try {
	resp.setContentType(command.getContentType());
	
	//resp.setContentLength(-1);
	OutputStream out = resp.getOutputStream();
	command.transfer(out);
	out.flush();
	
} catch (Throwable e) {
	e.printStackTrace();
	resp.setStatus(HttpServletResponse.SC_BAD_REQUEST, "Error:" + e.getMessage());
}		
  	return(null);
   }
 
開發者ID:luox12,項目名稱:onecmdb,代碼行數:23,代碼來源:RemoteController.java

示例5: onBindAndValidate

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
@Override
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception {
    
    super.onBindAndValidate(request, command, errors);
    SiteCommand site = (SiteCommand) command;
    
    
    // data is here bound into site, including the current action 
    SiteAction action = site.getAction();
    if (action == null) {
        // we are coming here without having an action 
        errors.addError(new ObjectError("SiteController", null, null, 
        "No Action set!"));
        return;
    }
    
    // initiate the action, via the parameters in the request
    ServletRequestDataBinder binder = new ServletRequestDataBinder(action);
    binder.bind(request);
    
}
 
開發者ID:luox12,項目名稱:onecmdb,代碼行數:22,代碼來源:SiteController.java

示例6: testBind

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
@Test
public void testBind() {
    command = new RouteAssignmentCommand();
    request = new MockHttpServletRequest();

    request.addParameter("legs[0].voyageNumber", "CM01");
    request.addParameter("legs[0].fromUnLocode", "AAAAA");
    request.addParameter("legs[0].toUnLocode", "BBBBB");

    request.addParameter("legs[1].voyageNumber", "CM02");
    request.addParameter("legs[1].fromUnLocode", "CCCCC");
    request.addParameter("legs[1].toUnLocode", "DDDDD");

    request.addParameter("trackingId", "XYZ");

    ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
    binder.bind(request);

    assertThat(command.getLegs()).hasSize(2).extracting("voyageNumber", "fromUnLocode", "toUnLocode")
            .containsAll(Arrays.asList(Tuple.tuple("CM01", "AAAAA", "BBBBB"), Tuple.tuple("CM02", "CCCCC", "DDDDD")));

    assertThat(command.getTrackingId()).isEqualTo("XYZ");
}
 
開發者ID:citerus,項目名稱:dddsample-core,代碼行數:24,代碼來源:ItinerarySelectionCommandTest.java

示例7: authHandler

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
   * Command(s)
   */
  
  /*
   * Auth Command.
   */
  public ModelAndView authHandler(HttpServletRequest request, HttpServletResponse resp) throws Exception {
getLog().info("AuthHandler()");
  	AuthCommand command = new AuthCommand(this.onecmdb);
  	ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
binder.bind(request);
	
try {
	String token = command.getToken();
	resp.setContentLength(token.length());
	resp.setContentType("text/plain");
	resp.getOutputStream().write(token.getBytes());
	
} catch (Exception e) {
	resp.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE, "Authentication Failed!");
}
  	return(null);
  }
 
開發者ID:luox12,項目名稱:onecmdb,代碼行數:25,代碼來源:RemoteController.java

示例8: validateAssertion

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * Validate assertion.
 *
 * @param request the request
 * @param serviceTicketId the service ticket id
 * @param assertion the assertion
 * @return the boolean
 */
private boolean validateAssertion(final HttpServletRequest request, final String serviceTicketId, final Assertion assertion) {
    final ValidationSpecification validationSpecification = this.getCommandClass();
    final ServletRequestDataBinder binder = new ServletRequestDataBinder(validationSpecification, "validationSpecification");
    initBinder(request, binder);
    binder.bind(request);

    if (!validationSpecification.isSatisfiedBy(assertion)) {
        logger.debug("Service ticket [{}] does not satisfy validation specification.", serviceTicketId);
        return false;
    }
    return true;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:21,代碼來源:AbstractServiceValidateController.java

示例9: validateAssertion

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * Validate assertion.
 *
 * @param request the request
 * @param serviceTicketId the service ticket id
 * @param assertion the assertion
 * @return true/false
 */
private boolean validateAssertion(final HttpServletRequest request, final String serviceTicketId, final Assertion assertion) {
    this.validationSpecification.reset();
    final ServletRequestDataBinder binder = new ServletRequestDataBinder(this.validationSpecification, "validationSpecification");
    initBinder(request, binder);
    binder.bind(request);
    
    if (!this.validationSpecification.isSatisfiedBy(assertion, request)) {
        LOGGER.warn("Service ticket [{}] does not satisfy validation specification.", serviceTicketId);
        return false;
    }
    return true;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:21,代碼來源:AbstractServiceValidateController.java

示例10: bind

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * Bind request parameters onto the given command bean
 * @param request request from which parameters will be bound
 * @param command command object, that must be a JavaBean
 * @throws Exception in case of invalid state or arguments
 */
protected void bind(HttpServletRequest request, Object command) throws Exception {
	logger.debug("Binding request parameters onto MultiActionController command");
	ServletRequestDataBinder binder = createBinder(request, command);
	binder.bind(request);
	if (this.validators != null) {
		for (Validator validator : this.validators) {
			if (validator.supports(command.getClass())) {
				ValidationUtils.invokeValidator(validator, command, binder.getBindingResult());
			}
		}
	}
	binder.closeNoCatch();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:MultiActionController.java

示例11: bindRequestParameters

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * This implementation downcasts {@link WebDataBinder} to
 * {@link ServletRequestDataBinder} before binding.
 * @see ServletRequestDataBinderFactory
 */
@Override
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
	ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
	servletBinder.bind(servletRequest);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:ServletModelAttributeMethodProcessor.java

示例12: bindRequestParameters

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request,MethodParameter parameter) {
	Namespace annot = parameter.getParameterAnnotation(Namespace.class);
	String attrName= (annot != null) ? annot.value() : null;
	if(StringUtils.hasText(attrName)){
		binder.setFieldDefaultPrefix(attrName+":");
	}
	ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
	ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
	servletBinder.bind(servletRequest);
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:11,代碼來源:NamespaceModelAttributeMethodProcessor.java

示例13: bindRequestParameters

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * This implementation downcasts {@link WebDataBinder} to
 * {@link ServletRequestDataBinder} before binding.
 * 
 * @see ServletRequestDataBinderFactory
 */
@Override
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
	ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
	ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
	servletBinder.bind(servletRequest);
}
 
開發者ID:xiangxik,項目名稱:java-platform,代碼行數:13,代碼來源:EntityModelAttributeMethodProcessor.java

示例14: resolveArgument

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    String name = UifConstants.DEFAULT_MODEL_NAME;

    Object attribute = null;
    if (mavContainer.containsAttribute(name)) {
        attribute = mavContainer.getModel().get(name);
    }

    WebDataBinder binder = binderFactory.createBinder(webRequest, attribute, name);
    if (binder.getTarget() != null) {
        ServletRequest servletRequest = webRequest.getNativeRequest(ServletRequest.class);
        ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
        servletBinder.bind(servletRequest);

        if (binder.getBindingResult().hasErrors()) {
            if (isBindExceptionRequired(parameter)) {
                throw new BindException(binder.getBindingResult());
            }
        }
    }

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

    return binder.getTarget();
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:33,代碼來源:UifDefaultFormMethodArgumentResolver.java

示例15: bind

import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
public void bind(ServletRequest request, ServletRequestDataBinder binder) {
	Map<String, ?> values = parseValues(request, binder);
	MutablePropertyValues mpvs = new MutablePropertyValues(values);
	MultipartRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartRequest.class);
	if (multipartRequest != null) {
		bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
	}
	// two lines copied from ExtendedServletRequestDataBinder
	String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	mpvs.addPropertyValues((Map<String, String>) request.getAttribute(attr));
	binder.bind(mpvs);
}
 
開發者ID:thunderbird,項目名稱:pungwecms,代碼行數:13,代碼來源:FormModelAttributeMethodProcessor.java


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