当前位置: 首页>>代码示例>>Java>>正文


Java StringTrimmerEditor类代码示例

本文整理汇总了Java中org.springframework.beans.propertyeditors.StringTrimmerEditor的典型用法代码示例。如果您正苦于以下问题:Java StringTrimmerEditor类的具体用法?Java StringTrimmerEditor怎么用?Java StringTrimmerEditor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringTrimmerEditor类属于org.springframework.beans.propertyeditors包,在下文中一共展示了StringTrimmerEditor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: withSingleValueAndEditor

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@Test
public void withSingleValueAndEditor() throws Exception {
	this.bean.setName("Rob Harrop");
	this.tag.setPath("name");
	this.tag.setValue("   Rob Harrop");
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
	bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, new StringTrimmerEditor(false));
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("name", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
	assertEquals("   Rob Harrop", checkboxElement.attribute("value").getValue());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:CheckboxTagTests.java

示例2: setCollectionPropertyWithStringValueAndCustomEditor

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@Test
public void setCollectionPropertyWithStringValueAndCustomEditor() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
	accessor.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));

	accessor.setPropertyValue("set", "set1 ");
	accessor.setPropertyValue("sortedSet", "sortedSet1");
	accessor.setPropertyValue("list", "list1 ");
	assertEquals(1, target.getSet().size());
	assertTrue(target.getSet().contains("set1"));
	assertEquals(1, target.getSortedSet().size());
	assertTrue(target.getSortedSet().contains("sortedSet1"));
	assertEquals(1, target.getList().size());
	assertTrue(target.getList().contains("list1"));

	accessor.setPropertyValue("list", Collections.singletonList("list1 "));
	assertTrue(target.getList().contains("list1"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:AbstractPropertyAccessorTests.java

示例3: testWithSingleValueAndEditor

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
public void testWithSingleValueAndEditor() throws Exception {
	this.bean.setName("Rob Harrop");
	this.tag.setPath("name");
	this.tag.setValue("   Rob Harrop");
	BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
	bindingResult.getPropertyEditorRegistry().registerCustomEditor(String.class, new StringTrimmerEditor(false));
	getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult);

	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();

	// wrap the output so it is valid XML
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element checkboxElement = (Element) document.getRootElement().elements().get(0);
	assertEquals("input", checkboxElement.getName());
	assertEquals("checkbox", checkboxElement.attribute("type").getValue());
	assertEquals("name", checkboxElement.attribute("name").getValue());
	assertEquals("checked", checkboxElement.attribute("checked").getValue());
	assertEquals("   Rob Harrop", checkboxElement.attribute("value").getValue());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:26,代码来源:CheckboxTagTests.java

示例4: testCollectionsWithStringValuesAndCustomEditor

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@Test
public void testCollectionsWithStringValuesAndCustomEditor() {
	IndexedTestBean tb = new IndexedTestBean();
	BeanWrapper bw = new BeanWrapperImpl(tb);
	bw.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
	bw.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));

	bw.setPropertyValue("set", "set1 ");
	bw.setPropertyValue("sortedSet", "sortedSet1");
	bw.setPropertyValue("list", "list1 ");
	assertEquals(1, tb.getSet().size());
	assertTrue(tb.getSet().contains("set1"));
	assertEquals(1, tb.getSortedSet().size());
	assertTrue(tb.getSortedSet().contains("sortedSet1"));
	assertEquals(1, tb.getList().size());
	assertTrue(tb.getList().contains("list1"));

	bw.setPropertyValue("list", Arrays.asList(new String[] {"list1 "}));
	assertTrue(tb.getList().contains("list1"));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:21,代码来源:BeanWrapperTests.java

示例5: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * Sets the require fields and the disallowed fields from the
 * HttpServletRequest.
 *
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 * org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(final HttpServletRequest request,
        final ServletRequestDataBinder binder) throws Exception {
    binder.setRequiredFields(new String[] {"description", "serviceId",
            "name", "allowedToProxy", "enabled", "ssoEnabled",
            "anonymousAccess", "evaluationOrder"});
    binder.setDisallowedFields(new String[] {"id"});
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:18,代码来源:RegisteredServiceSimpleFormController.java

示例6: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:8,代码来源:ExpedientTipusController.java

示例7: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	binder.registerCustomEditor(
			Object.class,
			new ObjectTypeEditorHelper());
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:11,代码来源:TascaLlistatV3Controller.java

示例8: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

    Object target = binder.getTarget();
    if (target != null) {
        binder.replaceValidators(supportedValidatorsFor(target.getClass()));
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:10,代码来源:CommonControllerAdvice.java

示例9: testConversionWithInappropriateStringEditor

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@Test
public void testConversionWithInappropriateStringEditor() {
	DataBinder dataBinder = new DataBinder(null);
	DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
	dataBinder.setConversionService(conversionService);
	dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));

	NameBean bean = new NameBean("Fred");
	assertEquals("ConversionService should have invoked toString()", "Fred", dataBinder.convertIfNecessary(bean, String.class));
	conversionService.addConverter(new NameBeanConverter());
	assertEquals("Type converter should have been used", "[Fred]", dataBinder.convertIfNecessary(bean, String.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:DataBinderTests.java

示例10: testGenericListOfArraysWithElementConversion

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@Test
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
	GenericBean<String> gb = new GenericBean<String>();
	ArrayList<String[]> list = new ArrayList<String[]>();
	list.add(new String[] {"str1", "str2"});
	gb.setListOfArrays(list);
	BeanWrapper bw = new BeanWrapperImpl(gb);
	bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
	assertEquals("str3", bw.getPropertyValue("listOfArrays[0][1]"));
	assertEquals("str3", gb.getListOfArrays().get(0)[1]);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:BeanWrapperGenericsTests.java

示例11: propertyTypeIndexedProperty

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@Test
public void propertyTypeIndexedProperty() {
	IndexedTestBean target = new IndexedTestBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	assertEquals(null, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.setPropertyValue("map[key0]", "my String");
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));

	accessor = createAccessor(target);
	accessor.registerCustomEditor(String.class, "map[key0]", new StringTrimmerEditor(false));
	assertEquals(String.class, accessor.getPropertyType("map[key0]"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:AbstractPropertyAccessorTests.java

示例12: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
public void initBinder(WebDataBinder binder, WebRequest request) {

		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
		binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	}
 
开发者ID:aramsoft,项目名称:aramcomp,代码行数:8,代码来源:BindingInitializer.java

示例13: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
/**
 * Registers the {@link StringTrimmerEditor}
 *
 * @param webDataBinder
 */
@InitBinder
public void initBinder(WebDataBinder webDataBinder) {
  StringTrimmerEditor trimmer =
      new StringTrimmerEditor(this.getCharsToDelete(), this.isEmptyAsNull());
  webDataBinder.registerCustomEditor(String.class, trimmer);
}
 
开发者ID:DISID,项目名称:springlets,代码行数:12,代码来源:StringTrimmerAdvice.java

示例14: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
public void initBinder(WebDataBinder binder, WebRequest request) {
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(false);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	binder.registerCustomEditor(PetType.class, new PetTypeEditor(this.clinic));
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:8,代码来源:ClinicBindingInitializer.java

示例15: initBinder

import org.springframework.beans.propertyeditors.StringTrimmerEditor; //导入依赖的package包/类
@InitBinder
public void initBinder(WebDataBinder binder) {

	binder.registerCustomEditor(MediaType.class, new MediaTypeEditor(
			MediaType.class));
	binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));/* Converts empty strings into null when a form is submitted */
}
 
开发者ID:PodcastpediaOrg,项目名称:podcastpedia-web,代码行数:8,代码来源:StartPageController.java


注:本文中的org.springframework.beans.propertyeditors.StringTrimmerEditor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。