List of usage examples for org.springframework.beans.propertyeditors StringTrimmerEditor StringTrimmerEditor
public StringTrimmerEditor(boolean emptyAsNull)
From source file:org.motechproject.server.omod.web.controller.PatientController.java
@InitBinder public void initBinder(WebDataBinder binder) { String datePattern = "dd/MM/yyyy"; SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dateFormat.setLenient(false);/*from w w w . ja va 2 s . c o m*/ binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true, datePattern.length())); String timePattern = MotechConstants.TIME_FORMAT_DELIVERY_TIME; SimpleDateFormat timeFormat = new SimpleDateFormat(timePattern); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, "timeOfDay", new CustomDateEditor(timeFormat, true, timePattern.length())); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:easycare.web.user.UserController.java
@InitBinder public void initBinder(WebDataBinder dataBinder) { CountryEditor countryEditor = new CountryEditor(this.regionCountryStateService); dataBinder.registerCustomEditor(Country.class, countryEditor); dataBinder.registerCustomEditor(State.class, new StateEditor(this.regionCountryStateService, countryEditor)); // bind empty strings as null dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:com.alliander.osgp.webdevicesimulator.web.controller.AbstractController.java
/** * Replace empty strings "" (default behavior) with null values on model * binding/*w w w .j a va2 s. c o m*/ */ @InitBinder protected void initBinder(final HttpServletRequest request, final ServletRequestDataBinder binder) throws Exception { // bind empty strings as null binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:com.sarm.aussiepayslipgenerator.view.PaySlipController.java
@InitBinder public void initBinder(WebDataBinder binder) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false);//from w w w .j a va2 s .com binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:de.siegmar.securetransfer.controller.SendController.java
private DataBinder initBinder() { final DataBinder binder = new DataBinder(new EncryptMessageCommand(), "command"); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); binder.setValidator(validator);//from w w w .j a va 2 s. co m return binder; }
From source file:org.hdiv.web.servlet.tags.form.CheckboxTagTests.java
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 = getWriter().toString(); // 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()); }
From source file:org.tonguetied.web.KeywordController.java
@Override protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Language.class, new LanguageSupport(keywordService.getLanguages())); binder.registerCustomEditor(Country.class, new CountrySupport(keywordService.getCountries())); binder.registerCustomEditor(Bundle.class, new BundleSupport(keywordService.getBundles())); binder.registerCustomEditor(TranslationState.class, new TranslationStateSupport()); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperGenericsTests.java
@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);// w w w . j av a 2s . c om BeanWrapper bw = new JuffrouSpringBeanWrapper(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]); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testTypeDeterminationForIndexedProperty() { BeanWrapper bw = new JuffrouSpringBeanWrapper(IndexedTestBean.class); assertEquals(null, bw.getPropertyType("map[key0]")); bw = new JuffrouSpringBeanWrapper(IndexedTestBean.class); bw.setPropertyValue("map[key0]", "my String"); assertEquals(String.class, bw.getPropertyType("map[key0]")); bw = new JuffrouSpringBeanWrapper(IndexedTestBean.class); bw.registerCustomEditor(String.class, "map[key0]", new StringTrimmerEditor(false)); assertEquals(String.class, bw.getPropertyType("map[key0]")); }
From source file:org.hdiv.web.servlet.tags.form.CheckboxTagTests.java
public void testWithMultiValueWithEditor() throws Exception { this.tag.setPath("stringArray"); this.tag.setValue(" foo"); 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 = getWriter().toString(); // 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("stringArray", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals(" foo", checkboxElement.attribute("value").getValue()); }