From: Chad B. <cwb...@us...> - 2008-05-15 17:58:01
|
User: cwbrandon Date: 08/05/15 10:57:49 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: handle non string property population Revision Changes Path 1.5 +27 -15 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/FormPopulator.java.vsl Index: FormPopulator.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/FormPopulator.java.vsl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- FormPopulator.java.vsl 3 Apr 2008 20:56:31 -0000 1.4 +++ FormPopulator.java.vsl 15 May 2008 17:57:48 -0000 1.5 @@ -135,29 +135,41 @@ org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(form, name); if (descriptor != null) { - final String property = (String)properties.get(name); + final Object property = properties.get(name); + // - only convert if the string is not empty - if (property != null && property.trim().length() > 0) + if (property != null) { Object value = null; + if (property instanceof String) + { + final String propertyAsString = (String)property; + if (propertyAsString.trim().length() > 0) + { java.text.DateFormat formatter = (java.text.DateFormat)formatters.get(name); // - if the formatter is available we use that, otherwise we attempt to convert if (formatter != null) { try { - value = formatter.parse(property); + value = formatter.parse(propertyAsString); } catch (java.text.ParseException parseException) { // - try the default formatter (handles the default java.util.Date.toString() format) formatter = (java.text.DateFormat)formatters.get(null); - value = formatter.parse(property); + value = formatter.parse(propertyAsString); + } + } + else + { + value = org.apache.commons.beanutils.ConvertUtils.convert(propertyAsString, descriptor.getPropertyType()); + } } } else { - value = org.apache.commons.beanutils.ConvertUtils.convert(property, descriptor.getPropertyType()); + value = property; } org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); } |