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


Java ServletRequestDataBinder類代碼示例

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


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

示例1: uriTemplateVarAndRequestParam

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Test
public void uriTemplateVarAndRequestParam() throws Exception {
	request.addParameter("age", "35");

	Map<String, String> uriTemplateVars = new HashMap<String, String>();
	uriTemplateVars.put("name", "nameValue");
	uriTemplateVars.put("age", "25");
	request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

	TestBean target = new TestBean();
	WebDataBinder binder = new ExtendedServletRequestDataBinder(target, "");
	((ServletRequestDataBinder) binder).bind(request);

	assertEquals("nameValue", target.getName());
	assertEquals(35, target.getAge());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:ExtendedServletRequestDataBinderTests.java

示例2: bindTagWithoutErrors

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Test
public void bindTagWithoutErrors() throws JspException {
	PageContext pc = createPageContext();
	Errors errors = new ServletRequestDataBinder(new TestBean(), "tb").getBindingResult();
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb");
	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", status.getExpression() == null);
	assertTrue("Correct value", status.getValue() == null);
	assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
	assertTrue("Correct isError", !status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 0);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 0);
	assertTrue("Correct errorCode", "".equals(status.getErrorCode()));
	assertTrue("Correct errorMessage", "".equals(status.getErrorMessage()));
	assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:BindTagTests.java

示例3: bindTagWithIndexedProperties

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Test
public void bindTagWithIndexedProperties() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	Errors errors = new ServletRequestDataBinder(tb, "tb").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()));
	assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
	assertTrue("Correct value", "name0".equals(((TestBean) status.getValue()).getName()));
	assertTrue("Correct isError", status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
	assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
	assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
	assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
	assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:BindTagTests.java

示例4: bindTagWithMappedProperties

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Test
public void bindTagWithMappedProperties() throws JspException {
	PageContext pc = createPageContext();
	IndexedTestBean tb = new IndexedTestBean();
	Errors errors = new ServletRequestDataBinder(tb, "tb").getBindingResult();
	errors.rejectValue("map[key1]", "code1", "message1");
	errors.rejectValue("map[key1]", "code2", "message2");
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);

	BindTag tag = new BindTag();
	tag.setPageContext(pc);
	tag.setPath("tb.map[key1]");
	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", "map[key1]".equals(status.getExpression()));
	assertTrue("Value is TestBean", status.getValue() instanceof TestBean);
	assertTrue("Correct value", "name4".equals(((TestBean) status.getValue()).getName()));
	assertTrue("Correct isError", status.isError());
	assertTrue("Correct errorCodes", status.getErrorCodes().length == 2);
	assertTrue("Correct errorMessages", status.getErrorMessages().length == 2);
	assertTrue("Correct errorCode", "code1".equals(status.getErrorCodes()[0]));
	assertTrue("Correct errorCode", "code2".equals(status.getErrorCodes()[1]));
	assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessages()[0]));
	assertTrue("Correct errorMessage", "message2".equals(status.getErrorMessages()[1]));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:BindTagTests.java

示例5: nestedPathWithBindTagWithIgnoreNestedPath

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Test
public void nestedPathWithBindTagWithIgnoreNestedPath() throws JspException {
	PageContext pc = createPageContext();
	Errors errors = new ServletRequestDataBinder(new TestBean(), "tb2").getBindingResult();
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb2", errors);

	NestedPathTag tag = new NestedPathTag();
	tag.setPath("tb");
	tag.setPageContext(pc);
	tag.doStartTag();

	BindTag bindTag = new BindTag();
	bindTag.setPageContext(pc);
	bindTag.setIgnoreNestedPath(true);
	bindTag.setPath("tb2.name");

	assertTrue("Correct doStartTag return value", bindTag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	assertTrue("Has status variable", status != null);
	assertEquals("tb2.name", status.getPath());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:BindTagTests.java

示例6: transformTagNonExistingValue

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Test
public void transformTagNonExistingValue() throws JspException {
	// first set up the pagecontext and the bean
	PageContext pc = createPageContext();
	TestBean tb = new TestBean();
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
	CustomDateEditor l = new CustomDateEditor(df, true);
	binder.registerCustomEditor(Date.class, l);
	pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());

	// try with non-existing value
	BindTag bind = new BindTag();
	bind.setPageContext(pc);
	bind.setPath("tb.name");
	bind.doStartTag();

	TransformTag transform = new TransformTag();
	transform.setPageContext(pc);
	transform.setValue(null);
	transform.setParent(bind);
	transform.setVar("theString2");
	transform.doStartTag();

	assertNull(pc.getAttribute("theString2"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:BindTagTests.java

示例7: createBinderInstance

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
/**
 * Look current Thread for {@link ServletRequestDataBinder} created by
 * {@link DataBinderMappingJackson2HttpMessageConverter}, if found return
 * it, otherwise it delegates on parent method.
 * 
 * @param target
 * @param objectName
 * @param request
 * @return ServletRequestDataBinder
 */
@Override
protected ServletRequestDataBinder createBinderInstance(Object target,
        String objectName, NativeWebRequest request) {
    try {
        ServletRequestDataBinder binder = (ServletRequestDataBinder) ThreadLocalUtil
                .getThreadVariable(BindingResult.MODEL_KEY_PREFIX
                        .concat("JSON_DataBinder"));
        if (binder != null) {
            return binder;
        }
        return super.createBinderInstance(target, objectName, request);
    }
    finally {
        ThreadLocalUtil.destroy();
    }
}
 
開發者ID:gvSIGAssociation,項目名稱:gvnix1,代碼行數:27,代碼來源:Jackson2ServletRequestDataBinderFactory.java

示例8: testInitBinder

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Test
public void testInitBinder()
{
    // Mock HTTP servlet request.
    HttpServletRequest request = mock(HttpServletRequest.class);

    // Mock servlet request data binder.
    ServletRequestDataBinder binder = mock(ServletRequestDataBinder.class);

    // Call the method under test.
    herdRestControllerAdvice.initBinder(request, binder);

    // Verify the external calls.
    verify(binder).registerCustomEditor(DelimitedFieldValues.class, delimitedFieldValuesEditor);
    verify(binder).registerCustomEditor(DateTime.class, dateTimeEditor);
    verifyNoMoreInteractions(binder);
    verifyNoMoreInteractionsHelper();
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:19,代碼來源:HerdRestControllerAdviceTest.java

示例9: parseValues

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
private Map<String, ?> parseValues(ServletRequest request, ServletRequestDataBinder binder) {
	Map<String, Object> params = Maps.newTreeMap();
	Assert.notNull(request, "Request must not be null!");
	Map<String, String> parameterMappings = getParameterMappings(request, binder);
	Enumeration<String> paramNames = request.getParameterNames();
	while (paramNames != null && paramNames.hasMoreElements()) {
		String paramName = paramNames.nextElement();
		String[] values = request.getParameterValues(paramName);

		String fieldName = parameterMappings.get(paramName);
		// no annotation exists, use the default - the param name=field name
		if (fieldName == null) {
			fieldName = paramName;
		}

		if (values == null || values.length == 0) {
			// Do nothing, no values found at all.
		} else if (values.length > 1) {
			params.put(fieldName, values);
		} else {
			params.put(fieldName, values[0]);
		}
	}

	return params;
}
 
開發者ID:thunderbird,項目名稱:pungwecms,代碼行數:27,代碼來源:FormModelAttributeMethodProcessor.java

示例10: bindRequestParameters

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Override
    protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
//        Object target = binder.getTarget();
//        Class<?> targetClass = target.getClass();
//        if (!replaceMap.containsKey(targetClass)) {
//            Map<String, String> mapping = analyzeClass(targetClass);
//            replaceMap.put(targetClass, mapping);
//        }
//        Map<String, String> mapping = replaceMap.get(targetClass);
//        SuishenWebDataBinder paramNameDataBinder = new SuishenWebDataBinder(target, binder.getObjectName(), mapping,
//                doUnderScoreTrans);
//
//        requestMappingHandlerAdapter.getWebBindingInitializer().initBinder(paramNameDataBinder, nativeWebRequest);
//        initBinder(paramNameDataBinder);
//
//        super.bindRequestParameters(paramNameDataBinder, nativeWebRequest);
        ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
        ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
        bind(servletRequest, servletBinder);
    }
 
開發者ID:superhj1987,項目名稱:spring-mvc-model-attribute-alias,代碼行數:21,代碼來源:SuishenServletModelAttributeMethodProcessor.java

示例11: initBinder

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
/**
 * Allows for Integers to be used as values in input tags. Normally, only strings and lists are
 * expected
 *
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 *      org.springframework.web.bind.ServletRequestDataBinder)
 */
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
	super.initBinder(request, binder);
	
	binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, true));
	binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true));
	binder.registerCustomEditor(java.util.Date.class, "valueDatetime", new CustomDateEditor(Context.getDateTimeFormat(),
	        true));
	binder.registerCustomEditor(java.util.Date.class, "valueTime", new CustomDateEditor(Context.getTimeFormat(), true));
	binder.registerCustomEditor(Location.class, new LocationEditor());
	binder.registerCustomEditor(java.lang.Boolean.class, new CustomBooleanEditor(true)); //allow for an empty boolean value
	binder.registerCustomEditor(Person.class, new PersonEditor());
	binder.registerCustomEditor(Order.class, new OrderEditor());
	binder.registerCustomEditor(Concept.class, new ConceptEditor());
	binder.registerCustomEditor(Location.class, new LocationEditor());
	binder.registerCustomEditor(Encounter.class, new EncounterEditor());
	binder.registerCustomEditor(Drug.class, new DrugEditor());
}
 
開發者ID:openmrs,項目名稱:openmrs-module-legacyui,代碼行數:25,代碼來源:ObsFormController.java

示例12: initBinder

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
/**
 * Allows for other Objects to be used as values in input tags. Normally, only strings and lists
 * are expected
 *
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 *      org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
	super.initBinder(request, binder);
	
	ConceptFormBackingObject commandObject = (ConceptFormBackingObject) binder.getTarget();
	
	NumberFormat nf = NumberFormat.getInstance(Context.getLocale());
	binder.registerCustomEditor(java.lang.Integer.class, new CustomNumberEditor(java.lang.Integer.class, nf, true));
	binder.registerCustomEditor(java.lang.Double.class, new CustomNumberEditor(java.lang.Double.class, nf, true));
	binder.registerCustomEditor(java.util.Date.class,
	    new CustomDateEditor(SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Context.getLocale()), true));
	binder.registerCustomEditor(org.openmrs.ConceptClass.class, new ConceptClassEditor());
	binder.registerCustomEditor(org.openmrs.ConceptDatatype.class, new ConceptDatatypeEditor());
	binder.registerCustomEditor(java.util.Collection.class, "concept.conceptSets", new ConceptSetsEditor(commandObject
	        .getConcept().getConceptSets()));
	binder.registerCustomEditor(java.util.Collection.class, "concept.answers", new ConceptAnswersEditor(commandObject
	        .getConcept().getAnswers(true)));
	binder.registerCustomEditor(org.openmrs.ConceptSource.class, new ConceptSourceEditor());
	binder.registerCustomEditor(ConceptMapType.class, new ConceptMapTypeEditor());
	binder.registerCustomEditor(ConceptReferenceTerm.class, new ConceptReferenceTermEditor());
}
 
開發者ID:openmrs,項目名稱:openmrs-module-legacyui,代碼行數:29,代碼來源:ConceptFormController.java

示例13: initBinder

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
@Override
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
	super.initBinder(request, binder);
	
       NumberFormat nf = NumberFormat.getInstance(request.getLocale());	
       
       // Register the binders.
       binder.registerCustomEditor(Long.class, "selectedPermission", new CustomNumberEditor(Long.class, nf, true));
	binder.registerCustomEditor(java.util.Date.class, "startDate", DateUtils.get().getFullDateEditor(true));
	binder.registerCustomEditor(java.util.Date.class, "endDate", DateUtils.get().getFullDateEditor(true));
	
	// If the session model is available, we want to register the Permission's
	// authorising agency editor.
	if(getEditorContext(request) != null) {
		//binder.registerCustomEditor(AuthorisingAgent.class, new PermissionAuthAgencyEditor(sessionModel.getAuthorisingAgents()));
		binder.registerCustomEditor(AuthorisingAgent.class, "authorisingAgent", new EditorContextObjectEditor(getEditorContext(request), AuthorisingAgent.class));
		binder.registerCustomEditor(Set.class, "urls", new UrlPatternCollectionEditor(Set.class, true, getEditorContext(request)));
	}
}
 
開發者ID:DIA-NZ,項目名稱:webcurator,代碼行數:20,代碼來源:SitePermissionHandler.java

示例14: prepareBinder

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
/**
 * Prepare the given binder, applying the specified MessageCodesResolver,
 * BindingErrorProcessor and PropertyEditorRegistrars (if any).
 * Called by {@link #createBinder}.
 * @param binder the new binder instance
 * @see #createBinder
 * @see #setMessageCodesResolver
 * @see #setBindingErrorProcessor
 */
protected final void prepareBinder(ServletRequestDataBinder binder) {
	if (useDirectFieldAccess()) {
		binder.initDirectFieldAccess();
	}
	if (this.messageCodesResolver != null) {
		binder.setMessageCodesResolver(this.messageCodesResolver);
	}
	if (this.bindingErrorProcessor != null) {
		binder.setBindingErrorProcessor(this.bindingErrorProcessor);
	}
	if (this.propertyEditorRegistrars != null) {
		for (int i = 0; i < this.propertyEditorRegistrars.length; i++) {
			this.propertyEditorRegistrars[i].registerCustomEditors(binder);
		}
	}
}
 
開發者ID:openmrs,項目名稱:openmrs-module-legacyui,代碼行數:26,代碼來源:BaseCommandController.java

示例15: initBinder

import org.springframework.web.bind.ServletRequestDataBinder; //導入依賴的package包/類
/**
 * Set up a custom property editor for converting form inputs to real
 * objects
 * 
 * @param request
 *            the current request
 * @param binder
 *            the data binder
 */
@InitBinder
protected void initBinder(HttpServletRequest request,
		ServletRequestDataBinder binder) {
	binder.registerCustomEditor(Integer.class, null,
			new CustomNumberEditor(Integer.class, null, true));
	binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(
			Long.class, null, true));
	binder.registerCustomEditor(byte[].class,
			new ByteArrayMultipartFileEditor());
	log.trace(request.getLocale());
	log.trace(getText("date.format", request.getLocale()));
	SimpleDateFormat dateFormat = new SimpleDateFormat(getText(
			"date.format", request.getLocale()));
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, null, new CustomDateEditor(
			dateFormat, true));
}
 
開發者ID:SMVBE,項目名稱:ldadmin,代碼行數:27,代碼來源:BaseFormController.java


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