本文整理汇总了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());
}
示例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"));
}
示例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());
}
示例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"));
}
示例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));
}
示例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));
}
示例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());
}
示例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()));
}
}
示例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));
}
示例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]);
}
示例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]"));
}
示例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));
}
示例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);
}
示例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));
}
示例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 */
}