List of usage examples for org.springframework.beans.propertyeditors CharacterEditor CharacterEditor
public CharacterEditor(boolean allowEmpty)
From source file:org.openmrs.web.controller.report.ReportObjectFormController.java
/** * Allows for Integers to be used as values in input tags. Normally, only strings and lists are * expected//from w w w . j a v a2s. c o m * * @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(Integer.class, new CustomNumberEditor(Integer.class, true)); binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, true)); binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, true)); binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, true)); binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor("t", "f", true)); binder.registerCustomEditor(Character.class, new CharacterEditor(true)); // TODO: check this for dates in both locales binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true)); binder.registerCustomEditor(Concept.class, new ConceptEditor()); binder.registerCustomEditor(Location.class, new LocationEditor()); binder.registerCustomEditor(User.class, new UserEditor()); }
From source file:org.nextframework.controller.ExtendedBeanWrapper.java
/** * Register default editors in this class, for restricted environments. * We're not using the JRE's PropertyEditorManager to avoid potential * SecurityExceptions when running in a SecurityManager. * <p>Registers a <code>CustomNumberEditor</code> for all primitive number types, * their corresponding wrapper types, <code>BigInteger</code> and <code>BigDecimal</code>. *//*from w ww . j a va 2 s . c o m*/ protected void registerDefaultEditors() { // Simple editors, without parameterization capabilities. // The JDK does not contain a default editor for any of these target types. this.defaultEditors.put(byte[].class, new ByteArrayPropertyEditor()); this.defaultEditors.put(Class.class, new ClassEditor()); this.defaultEditors.put(File.class, new FileEditor()); this.defaultEditors.put(InputStream.class, new InputStreamEditor()); this.defaultEditors.put(Locale.class, new LocaleEditor()); this.defaultEditors.put(Properties.class, new PropertiesEditor()); this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor()); this.defaultEditors.put(String[].class, new StringArrayPropertyEditor()); this.defaultEditors.put(URL.class, new URLEditor()); // Default instances of collection editors. // Can be overridden by registering custom instances of those as custom editors. this.defaultEditors.put(Collection.class, new CustomCollectionEditor(Collection.class)); this.defaultEditors.put(Set.class, new CustomCollectionEditor(Set.class)); this.defaultEditors.put(SortedSet.class, new CustomCollectionEditor(SortedSet.class)); this.defaultEditors.put(List.class, new CustomCollectionEditor(List.class)); // Default instances of character and boolean editors. // Can be overridden by registering custom instances of those as custom editors. PropertyEditor characterEditor = new CharacterEditor(true); PropertyEditor booleanEditor = new CustomBooleanEditor(true); // The JDK does not contain a default editor for char! this.defaultEditors.put(char.class, characterEditor); this.defaultEditors.put(Character.class, characterEditor); // Spring's CustomBooleanEditor accepts more flag values than the JDK's default editor. this.defaultEditors.put(boolean.class, booleanEditor); this.defaultEditors.put(Boolean.class, booleanEditor); // The JDK does not contain default editors for number wrapper types! // Override JDK primitive number editors with our own CustomNumberEditor. PropertyEditor byteEditor = new CustomNumberEditor(Byte.class, true); PropertyEditor shortEditor = new CustomNumberEditor(Short.class, true); PropertyEditor integerEditor = new CustomNumberEditor(Integer.class, true); PropertyEditor longEditor = new CustomNumberEditor(Long.class, true); PropertyEditor floatEditor = new CustomNumberEditor(Float.class, true); PropertyEditor doubleEditor = new CustomNumberEditor(Double.class, true); this.defaultEditors.put(byte.class, byteEditor); this.defaultEditors.put(Byte.class, byteEditor); this.defaultEditors.put(short.class, shortEditor); this.defaultEditors.put(Short.class, shortEditor); this.defaultEditors.put(int.class, integerEditor); this.defaultEditors.put(Integer.class, integerEditor); this.defaultEditors.put(long.class, longEditor); this.defaultEditors.put(Long.class, longEditor); this.defaultEditors.put(float.class, floatEditor); this.defaultEditors.put(Float.class, floatEditor); this.defaultEditors.put(double.class, doubleEditor); this.defaultEditors.put(Double.class, doubleEditor); this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, false)); this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, false)); //============================================================================================ // Date, Time, Hora e Timestamp. boolean allowEmpty = true; registerCustomEditor(Calendar.class, new CalendarEditor(simpleDateFormat, allowEmpty)); registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, allowEmpty)); registerCustomEditor(java.sql.Date.class, new CustomSqlDateEditor(simpleDateFormat, allowEmpty)); registerCustomEditor(Time.class, new TimePropertyEditor()); registerCustomEditor(SimpleTime.class, new SimpleTimePropertyEditor()); registerCustomEditor(Timestamp.class, new TimestampPropertyEditor()); // Tipos personalizados. registerCustomEditor(Cpf.class, new CpfPropertyEditor()); registerCustomEditor(Cnpj.class, new CnpjPropertyEditor()); registerCustomEditor(InscricaoEstadual.class, new InscricaoEstadualPropertyEditor()); registerCustomEditor(Money.class, new MoneyPropertyEditor()); registerCustomEditor(Cep.class, new CepPropertyEditor()); registerCustomEditor(PhoneBrazil.class, new PhoneBrazilPropertyEditor()); registerCustomEditor(Phone.class, new PhonePropertyEditor()); }