From: Chad B. <cwb...@us...> - 2007-09-26 17:59:24
|
User: cwbrandon Date: 07/09/26 10:59:28 Modified: andromda-jsf2/src/main/resources/templates/jsf2/controllers Controller.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: add ability to ignore population of id attribute Revision Changes Path 1.6 +3 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl Index: Controller.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -r1.5 -r1.6 --- Controller.java.vsl 26 Sep 2007 15:46:03 -0000 1.5 +++ Controller.java.vsl 26 Sep 2007 17:59:27 -0000 1.6 @@ -55,8 +55,10 @@ // - pass any properties from the previous form along ${managedBeansPackage}.${formPopulatorName}.populateForm(currentForm, form); // - populate the form with any event attributes that may match + // IMPORTANT: it isn't possible to automatically populate any property named "id" since that + // is a reserved name in JSF (the id of a component), therefore we have to unfortunately ignore any availble "id" attribute ${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap( - form, form.getDateTimeFormatters(), (java.util.Map)this.getRequest().getAttribute(ACTION_EVENT_ATTRIBUTES)); + form, form.getDateTimeFormatters(), (java.util.Map)this.getRequest().getAttribute(ACTION_EVENT_ATTRIBUTES), new String[] {"id"}); // - populate the form with any request parameters that may match ${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap( form, form.getDateTimeFormatters(), this.getContext().getExternalContext().getRequestParameterMap()); 1.3 +16 -1 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.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- FormPopulator.java.vsl 19 Sep 2007 16:50:53 -0000 1.2 +++ FormPopulator.java.vsl 26 Sep 2007 17:59:28 -0000 1.3 @@ -104,15 +104,30 @@ */ public static final void populateFormFromPropertyMap(final Object form, final java.util.Map formatters, final java.util.Map properties) { + populateFormFromPropertyMap(form, formatters, properties, null); + } + + /** + * Populates the form from the given map of properties. If a matching property is null or an empty + * string, then null is placed on the form. + * + * @param form the form to populate. + * @param formatters any date or time formatters. + * @param properties the properties to populate from. + * @param ignoreProperties names of any properties to ignore when it comes to populating on the form. + */ + public static final void populateFormFromPropertyMap(final Object form, final java.util.Map formatters, final java.util.Map properties, final String[] ignoreProperties) + { if (properties != null) { try { + final java.util.Collection ignoredProperties = ignoreProperties != null ? java.util.Arrays.asList(ignoreProperties) : java.util.Collections.EMPTY_LIST; final java.util.Map formProperties = org.apache.commons.beanutils.PropertyUtils.describe(form); for (final java.util.Iterator iterator = formProperties.keySet().iterator(); iterator.hasNext();) { final String name = (String)iterator.next(); - if (org.apache.commons.beanutils.PropertyUtils.isWriteable(form, name)) + if (org.apache.commons.beanutils.PropertyUtils.isWriteable(form, name) && !ignoredProperties.contains(name)) { final java.beans.PropertyDescriptor descriptor = org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(form, name); |