From: Chad B. <cwb...@us...> - 2007-09-19 16:50:51
|
User: cwbrandon Date: 07/09/19 09:50:54 Modified: andromda-jsf2/src/main/resources/templates/jsf2/views/facelets view-table.xhtml.vsl andromda-jsf2/src/main/resources/templates/jsf2/controllers Controller.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: use actionListeners to pass attributes on table links (since commandButton's don't work with f:param anymore) Revision Changes Path 1.4 +3 -3 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/views/facelets/view-table.xhtml.vsl Index: view-table.xhtml.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/views/facelets/view-table.xhtml.vsl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- view-table.xhtml.vsl 19 Jul 2007 18:09:30 -0000 1.3 +++ view-table.xhtml.vsl 19 Sep 2007 16:50:52 -0000 1.4 @@ -8,7 +8,7 @@ #else #set ($parameterValue = "$parameter.name") #end - <f:param name="$parameter.name" value="#{${parameterValue}}"/> + <f:attribute name="$parameter.name" value="#{${parameterValue}}"/> #end #end <html xmlns="http://www.w3.org/1999/xhtml" @@ -74,7 +74,7 @@ <h:panelGroup styleClass="actionColumn"><t:graphicImage url="/images/space.gif"/></h:panelGroup> </f:facet> <h:panelGroup styleClass="actionColumn"> - <tr:commandLink text="#{messages['$action.trigger.messageKey']}" action="#{${action.controller.beanName}.${action.triggerName}}"> + <tr:commandLink text="#{messages['$action.trigger.messageKey']}" action="#{${action.controller.beanName}.${action.triggerName}}" actionListener="#{${action.controller.beanName}.action}"> #renderTableCommandLinkParameters() </tr:commandLink> </h:panelGroup> @@ -89,7 +89,7 @@ <h:panelGroup styleClass="actionColumn"><t:graphicImage url="/images/space.gif"/></h:panelGroup> </f:facet> <h:panelGroup styleClass="actionColumn"> - <tr:commandButton text="#{messages['$action.trigger.messageKey']}" action="#{${action.controller.beanName}.${action.triggerName}}"> + <tr:commandButton text="#{messages['$action.trigger.messageKey']}" action="#{${action.controller.beanName}.${action.triggerName}}" actionListener="#{${action.controller.beanName}.action}"> #renderTableCommandLinkParameters() </tr:commandButton> </h:panelGroup> 1.4 +22 -60 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.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- Controller.java.vsl 31 Aug 2007 15:32:51 -0000 1.3 +++ Controller.java.vsl 19 Sep 2007 16:50:53 -0000 1.4 @@ -52,10 +52,13 @@ final $action.fullyQualifiedFormImplementationName form = this.$action.formImplementationGetter; - // - pass any parameters from the previous form along + // - pass any properties from the previous form along ${managedBeansPackage}.${formPopulatorName}.populateForm(currentForm, form); // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); + ${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap( + form, form.getDateTimeFormatters(), this.getContext().getExternalContext().getRequestParameterMap()); + ${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap( + form, form.getDateTimeFormatters(), (java.util.Map)this.getRequest().getAttribute(ACTION_EVENT_ATTRIBUTES)); #end try { @@ -337,63 +340,6 @@ #if ($formPopulationOperationRequired) /** - * Populates the form from the given parameters. If the request parameter 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. - */ - private final void populateFormFromRequestParameters(final Object form, final java.util.Map formatters) - { - try - { - final java.util.Map parameters = this.getContext().getExternalContext().getRequestParameterMap(); - for (final java.util.Iterator iterator = parameters.keySet().iterator(); iterator.hasNext();) - { - final String name = (String)iterator.next(); - if (org.apache.commons.beanutils.PropertyUtils.isWriteable(form, name)) - { - final java.beans.PropertyDescriptor descriptor = - org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(form, name); - if (descriptor != null) - { - final String parameter = (String)parameters.get(name); - Object value = null; - // - only convert if the string is not empty - if (parameter != null && parameter.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(parameter); - } - 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(parameter); - } - } - else - { - value = org.apache.commons.beanutils.ConvertUtils.convert(parameter, descriptor.getPropertyType()); - } - org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); - } - } - } - } - } - catch (final Throwable throwable) - { - throw new RuntimeException(throwable); - } - } - - /** * Finds the form (if one is present) on the given <code>component</code> having the given * <code>id</code>. * @@ -547,4 +493,20 @@ } #end + /** + * The name of the request attribute that stores the attributes from the current action event. + */ + private static final String ACTION_EVENT_ATTRIBUTES = "actionEventAttributes"; + + /** + * This method just captures the event attributes and sets them into the request + * so that we can retrieve in controller action operation and use to populate form. + * + * @param event the action event. + */ + public void action(javax.faces.event.ActionEvent event) + { + this.getRequest().setAttribute(ACTION_EVENT_ATTRIBUTES, event.getComponent(). + getAttributes()); + } } 1.2 +65 -6 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.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- FormPopulator.java.vsl 5 Dec 2006 19:39:21 -0000 1.1 +++ FormPopulator.java.vsl 19 Sep 2007 16:50:53 -0000 1.2 @@ -12,8 +12,7 @@ implements java.io.Serializable { /** - * Populates the form from the given parameters. If the request parameter is null or an empty - * string, then null is placed on the form. + * Copies the properties from the <code>fromForm</code> to the <code>toForm</code>. Only passes not-null values to the toForm. * * @param fromForm the form from which we're populating * @param toForm the form to which we're populating @@ -24,8 +23,7 @@ } /** - * Populates the form from the given parameters. If the request parameter is null or an empty - * string, then null is placed on the form. + * Copies the properties from the <code>fromForm</code> to the <code>toForm</code>. Only passes not-null values to the toForm. * * @param fromForm the form from which we're populating * @param toForm the form to which we're populating @@ -55,7 +53,7 @@ isToFormPropertySet = (java.lang.Boolean)org.apache.commons.beanutils.PropertyUtils.getProperty(toForm, isSetPropertyName); } } - // - only if override is set to true, do we check to see if the from form property has been set + // - only if override is set to true, we check to see if the from form property has been set if (override) { if (org.apache.commons.beanutils.PropertyUtils.isReadable(fromForm, isSetPropertyName)) @@ -95,4 +93,65 @@ } } } + + /** + * 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. + */ + public static final void populateFormFromPropertyMap(final Object form, final java.util.Map formatters, final java.util.Map properties) + { + if (properties != null) + { + try + { + 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)) + { + final java.beans.PropertyDescriptor descriptor = + org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(form, name); + if (descriptor != null) + { + final String property = (String)properties.get(name); + // - only convert if the string is not empty + if (property != null && property.trim().length() > 0) + { + Object value = null; + 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); + } + 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); + } + } + else + { + value = org.apache.commons.beanutils.ConvertUtils.convert(property, descriptor.getPropertyType()); + } + org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); + } + } + } + } + } + catch (final Throwable throwable) + { + throw new RuntimeException(throwable); + } + } + } } \ No newline at end of file |
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); |
From: Chad B. <cwb...@us...> - 2008-04-03 20:56:27
|
User: cwbrandon Date: 08/04/03 13:56:31 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: add default serial version UID Revision Changes Path 1.4 +2 -0 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.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- FormPopulator.java.vsl 26 Sep 2007 17:59:28 -0000 1.3 +++ FormPopulator.java.vsl 3 Apr 2008 20:56:31 -0000 1.4 @@ -11,6 +11,8 @@ public class $formPopulatorName implements java.io.Serializable { + private static final long serialVersionUID = 1L; + /** * Copies the properties from the <code>fromForm</code> to the <code>toForm</code>. Only passes not-null values to the toForm. * |
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); } |
From: Chad B. <cwb...@us...> - 2008-05-20 00:32:35
|
User: cwbrandon Date: 08/05/19 17:32:40 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: remove bogus condition Revision Changes Path 1.6 +12 -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.5 retrieving revision 1.6 diff -u -w -r1.5 -r1.6 --- FormPopulator.java.vsl 15 May 2008 17:57:48 -0000 1.5 +++ FormPopulator.java.vsl 20 May 2008 00:32:40 -0000 1.6 @@ -63,8 +63,6 @@ isFromFormPropertySet = (java.lang.Boolean)org.apache.commons.beanutils.PropertyUtils.getProperty(fromForm, isSetPropertyName); } } - if (!override || (override && isFromFormPropertySet != null && isFromFormPropertySet.booleanValue())) - { if (override || (isToFormPropertySet == null || !isToFormPropertySet.booleanValue())) { final java.beans.PropertyDescriptor toDescriptor = @@ -88,7 +86,6 @@ } } } - } catch (final Throwable throwable) { throw new RuntimeException(throwable); |
From: Chad B. <cwb...@us...> - 2008-05-20 02:54:28
|
User: cwbrandon Date: 08/05/19 19:54:29 Modified: andromda-jsf2/src/main/resources/templates/jsf2/forms FormImpl.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: add condition back (shouldn't have removed it). Just make sure we set complex objects "set" flags when they are created by default Revision Changes Path 1.5 +1 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/forms/FormImpl.java.vsl Index: FormImpl.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/forms/FormImpl.java.vsl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- FormImpl.java.vsl 17 Apr 2008 20:41:51 -0000 1.4 +++ FormImpl.java.vsl 20 May 2008 02:54:29 -0000 1.5 @@ -46,6 +46,7 @@ if (this.$field.name == null) { this.$field.name = new ${field.type.fullyQualifiedName}(); + this.${field.setterName}(this.$field.name); } #end return this.${field.name}; 1.7 +15 -12 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.6 retrieving revision 1.7 diff -u -w -r1.6 -r1.7 --- FormPopulator.java.vsl 20 May 2008 00:32:40 -0000 1.6 +++ FormPopulator.java.vsl 20 May 2008 02:54:29 -0000 1.7 @@ -63,6 +63,8 @@ isFromFormPropertySet = (java.lang.Boolean)org.apache.commons.beanutils.PropertyUtils.getProperty(fromForm, isSetPropertyName); } } + if (!override || (override && isFromFormPropertySet != null && isFromFormPropertySet.booleanValue())) + { if (override || (isToFormPropertySet == null || !isToFormPropertySet.booleanValue())) { final java.beans.PropertyDescriptor toDescriptor = @@ -86,6 +88,7 @@ } } } + } catch (final Throwable throwable) { throw new RuntimeException(throwable); |
From: Chad B. <cwb...@us...> - 2008-06-03 21:21:55
|
User: cwbrandon Date: 08/06/03 14:22:04 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: improve error message for copying of non-compatible types Revision Changes Path 1.8 +11 -0 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.7 retrieving revision 1.8 diff -u -w -r1.7 -r1.8 --- FormPopulator.java.vsl 20 May 2008 02:54:29 -0000 1.7 +++ FormPopulator.java.vsl 3 Jun 2008 21:22:02 -0000 1.8 @@ -170,6 +170,17 @@ else { value = property; + if (value != null) + { + if (!descriptor.getPropertyType().isAssignableFrom(value.getClass())) + { + final String propertyTypeName = descriptor.getPropertyType().getName(); + final String valueTypeName = value.getClass().getName(); + throw new java.lang.IllegalArgumentException("Can not set form property '" + + name + "' of type: " + propertyTypeName + " with value: " + + value + "; " + valueTypeName + " is not assignable to " + propertyTypeName); + } + } } org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); } |
From: Walter M. <wal...@us...> - 2008-07-02 11:51:16
|
User: walterim Date: 08/07/02 04:51:24 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: Removing correcting a hard coded reference to JsfUtils Revision Changes Path 1.10 +2 -2 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.9 retrieving revision 1.10 diff -u -w -r1.9 -r1.10 --- FormPopulator.java.vsl 1 Jul 2008 15:42:42 -0000 1.9 +++ FormPopulator.java.vsl 2 Jul 2008 11:51:24 -0000 1.10 @@ -106,13 +106,13 @@ public static final void populateFormFromRequestAttributes(final Object form, final java.util.Map formatters) { final javax.faces.context.FacesContext context = javax.faces.context.FacesContext.getCurrentInstance(); - final String[] names = org.andromda.presentation.jsf2.JsfUtils.getAttributeNames(context.getExternalContext().getRequest()); + final String[] names = ${managedBeansPackage}.JsfUtils.getAttributeNames(context.getExternalContext().getRequest()); final java.util.Map<String, Object> attributes = new java.util.LinkedHashMap<String, Object>(); if (names != null) { for (final String name : names) { - attributes.put(name, org.andromda.presentation.jsf2.JsfUtils.getAttribute(context.getExternalContext().getRequest(), name)); + attributes.put(name, ${managedBeansPackage}.JsfUtils.getAttribute(context.getExternalContext().getRequest(), name)); } } populateFormFromPropertyMap(form, formatters, attributes); |
From: Chad B. <cwb...@us...> - 2008-07-02 23:44:30
|
User: cwbrandon Date: 08/07/02 16:44:38 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: improve error handling Revision Changes Path 1.11 +14 -5 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.10 retrieving revision 1.11 diff -u -w -r1.10 -r1.11 --- FormPopulator.java.vsl 2 Jul 2008 11:51:24 -0000 1.10 +++ FormPopulator.java.vsl 2 Jul 2008 23:44:38 -0000 1.11 @@ -188,23 +188,32 @@ value = org.apache.commons.beanutils.ConvertUtils.convert(propertyAsString, descriptor.getPropertyType()); } } + org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); } else { value = property; if (value != null) { - if (!descriptor.getPropertyType().isAssignableFrom(value.getClass())) + try + { + org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); + } + catch (Exception exception) { - final String propertyTypeName = descriptor.getPropertyType().getName(); final String valueTypeName = value.getClass().getName(); - throw new java.lang.IllegalArgumentException("Can not set form property '" + final String propertyTypeName = descriptor.getPropertyType().getName(); + final StringBuffer message = new StringBuffer("Can not set form property '" + name + "' of type: " + propertyTypeName + " with value: " - + value + "; " + valueTypeName + " is not assignable to " + propertyTypeName); + + value); + if (!descriptor.getPropertyType().isAssignableFrom(value.getClass())) + { + message.append("; " + valueTypeName + " is not assignable to " + propertyTypeName); + } + throw new java.lang.IllegalArgumentException(message + ": " + exception.toString()); } } } - org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); } } } |
From: Chad B. <cwb...@us...> - 2008-07-03 18:27:09
|
User: cwbrandon Date: 08/07/03 11:27:18 Modified: andromda-jsf2/src/main/resources/templates/jsf2/flow ViewPopulator.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet PortletPhaseListener.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/controllers Controller.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: improve population from request attributes (don't override values that are already set). Also don't populate view variables with values that haven't been already set on the form. Revision Changes Path 1.11 +11 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl Index: ViewPopulator.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl,v retrieving revision 1.10 retrieving revision 1.11 diff -u -w -r1.10 -r1.11 --- ViewPopulator.java.vsl 3 Jul 2008 16:33:04 -0000 1.10 +++ ViewPopulator.java.vsl 3 Jul 2008 18:27:17 -0000 1.11 @@ -187,7 +187,17 @@ final boolean $readableVariable = org.apache.commons.beanutils.PropertyUtils.isReadable(form, "$variable.name"); if ($readableVariable) { - request.setAttribute("$variable.name", org.apache.commons.beanutils.PropertyUtils.getProperty(form, "$variable.name")); + java.lang.Boolean propertySet = null; + final String isSetPropertyName = "${variable.name}Set"; + if (org.apache.commons.beanutils.PropertyUtils.isReadable(form, isSetPropertyName)) + { + propertySet = (java.lang.Boolean)org.apache.commons.beanutils.PropertyUtils.getProperty(form, isSetPropertyName); + } + // - only set the property if its been set, or we can't tell if it has + if (propertySet == null || propertySet) + { + request.setAttribute("${variable.name}", org.apache.commons.beanutils.PropertyUtils.getProperty(form, "${variable.name}")); + } #if ($variable.reset) // reset $variable.name (since the model indicates that it should be reset) org.apache.commons.beanutils.PropertyUtils.setProperty(form, "$variable.name", $variable.type.javaNullString); 1.15 +2 -3 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet/PortletPhaseListener.java.vsl Index: PortletPhaseListener.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet/PortletPhaseListener.java.vsl,v retrieving revision 1.14 retrieving revision 1.15 diff -u -w -r1.14 -r1.15 --- PortletPhaseListener.java.vsl 1 Jul 2008 15:42:41 -0000 1.14 +++ PortletPhaseListener.java.vsl 3 Jul 2008 18:27:18 -0000 1.15 @@ -70,9 +70,9 @@ event.getFacesContext(), null, controller.${useCase.controllerAction}()); // - get the new view id before population since we are navigating to a new view viewId = event.getFacesContext().getViewRoot().getViewId(); - this.populateView(event, viewId); } #end + this.populateView(event, viewId); } else if (javax.faces.event.PhaseId.APPLY_REQUEST_VALUES.equals(event.getPhaseId())) { @@ -112,8 +112,7 @@ protected void handleAfterPhase(javax.faces.event.PhaseEvent event) { final String viewId = this.getViewId(event); - if (javax.faces.event.PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId()) || - javax.faces.event.PhaseId.APPLY_REQUEST_VALUES.equals(event.getPhaseId())) + if (javax.faces.event.PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) { this.populateView(event, viewId); } 1.20 +1 -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.19 retrieving revision 1.20 diff -u -w -r1.19 -r1.20 --- Controller.java.vsl 1 Jul 2008 15:42:42 -0000 1.19 +++ Controller.java.vsl 3 Jul 2008 18:27:18 -0000 1.20 @@ -64,7 +64,7 @@ ${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap( form, form.getDateTimeFormatters(), (java.util.Map)this.getRequestAttribute(ACTION_EVENT_ATTRIBUTES), new String[] {"id"}); // - populate the form with any request attributes that may match - ${managedBeansPackage}.${formPopulatorName}.populateFormFromRequestAttributes(form, form.getDateTimeFormatters()); + ${managedBeansPackage}.${formPopulatorName}.populateFormFromRequestAttributes(form, form.getDateTimeFormatters(), false); // - populate the form with any request parameters that may match ${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap( form, form.getDateTimeFormatters(), this.getContext().getExternalContext().getRequestParameterMap()); 1.12 +92 -44 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.11 retrieving revision 1.12 diff -u -w -r1.11 -r1.12 --- FormPopulator.java.vsl 2 Jul 2008 23:44:38 -0000 1.11 +++ FormPopulator.java.vsl 3 Jul 2008 18:27:18 -0000 1.12 @@ -102,8 +102,9 @@ * @param form the form to populate. * @param formatters any date or time formatters. * @param request the request object from which to populate attributes. + * @param override whether or not to override properties already set on the given form. */ - public static final void populateFormFromRequestAttributes(final Object form, final java.util.Map formatters) + public static final void populateFormFromRequestAttributes(final Object form, final java.util.Map formatters, boolean override) { final javax.faces.context.FacesContext context = javax.faces.context.FacesContext.getCurrentInstance(); final String[] names = ${managedBeansPackage}.JsfUtils.getAttributeNames(context.getExternalContext().getRequest()); @@ -115,7 +116,21 @@ attributes.put(name, ${managedBeansPackage}.JsfUtils.getAttribute(context.getExternalContext().getRequest(), name)); } } - populateFormFromPropertyMap(form, formatters, attributes); + populateFormFromPropertyMap(form, formatters, attributes, override); + } + + /** + * 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 override whether or not to override properties already set on the given form. + */ + public static final void populateFormFromPropertyMap(final Object form, final java.util.Map formatters, final java.util.Map properties, boolean override) + { + populateFormFromPropertyMap(form, formatters, properties, null, override); } /** @@ -128,7 +143,7 @@ */ public static final void populateFormFromPropertyMap(final Object form, final java.util.Map formatters, final java.util.Map properties) { - populateFormFromPropertyMap(form, formatters, properties, null); + populateFormFromPropertyMap(form, formatters, properties, null, true); } /** @@ -140,7 +155,24 @@ * @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) + public static final void populateFormFromPropertyMap(final Object form, final java.util.Map formatters, + final java.util.Map properties, final String[] ignoreProperties) + { + populateFormFromPropertyMap(form, formatters, properties, ignoreProperties, true); + } + + /** + * 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. + * @param override whether or not to override properties already set on the given form. + */ + public static final void populateFormFromPropertyMap(final Object form, final java.util.Map formatters, + final java.util.Map properties, final String[] ignoreProperties, boolean override) { if (properties != null) { @@ -157,6 +189,21 @@ org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(form, name); if (descriptor != null) { + boolean populateProperty = true; + if (!override) + { + final String isSetPropertyName = name + "Set"; + if (org.apache.commons.beanutils.PropertyUtils.isReadable(form, isSetPropertyName)) + { + final boolean isPropertySet = (java.lang.Boolean)org.apache.commons.beanutils.PropertyUtils.getProperty(form, isSetPropertyName); + if (isPropertySet) + { + populateProperty = false; + } + } + } + if (populateProperty) + { final Object property = properties.get(name); // - only convert if the string is not empty @@ -219,6 +266,7 @@ } } } + } catch (final Throwable throwable) { throw new RuntimeException(throwable); |
From: Chad B. <cwb...@us...> - 2008-07-07 18:21:40
|
User: cwbrandon Date: 08/07/07 11:21:49 Modified: andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet PortletPhaseListener.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: improve population of properties from parameters in the portlet phase listener Revision Changes Path 1.17 +14 -2 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet/PortletPhaseListener.java.vsl Index: PortletPhaseListener.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet/PortletPhaseListener.java.vsl,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -r1.16 -r1.17 --- PortletPhaseListener.java.vsl 3 Jul 2008 21:42:15 -0000 1.16 +++ PortletPhaseListener.java.vsl 7 Jul 2008 18:21:48 -0000 1.17 @@ -35,10 +35,22 @@ final javax.portlet.PortletRequest request = (javax.portlet.PortletRequest)event.getFacesContext().getExternalContext().getRequest(); final String currentUrl = (String)request.getAttribute(CURRENT_URL); final java.util.Map<String, Object> parameters = ${managedBeansPackage}.JsfUtils.extractParameters(currentUrl); + if (parameters != null && !parameters.isEmpty()) + { + final javax.faces.context.FacesContext context = event.getFacesContext(); + final Object form = context.getApplication().getVariableResolver().resolveVariable(context, "$actionFormKey"); + if (form != null) + { + ${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap(form, null, parameters); + } + else + { for (final String parameter : parameters.keySet()) { request.setAttribute(parameter, parameters.get(parameter)); } + } + } #end // - make the faces context available to all views ((javax.portlet.PortletRequest)event.getFacesContext().getExternalContext().getRequest()).setAttribute(FACES_CONTEXT, event.getFacesContext()); 1.13 +2 -2 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.12 retrieving revision 1.13 diff -u -w -r1.12 -r1.13 --- FormPopulator.java.vsl 3 Jul 2008 18:27:18 -0000 1.12 +++ FormPopulator.java.vsl 7 Jul 2008 18:21:49 -0000 1.13 @@ -215,7 +215,7 @@ final String propertyAsString = (String)property; if (propertyAsString.trim().length() > 0) { - java.text.DateFormat formatter = (java.text.DateFormat)formatters.get(name); + java.text.DateFormat formatter = formatters != null ? (java.text.DateFormat)formatters.get(name) : null; // - if the formatter is available we use that, otherwise we attempt to convert if (formatter != null) { @@ -226,7 +226,7 @@ catch (java.text.ParseException parseException) { // - try the default formatter (handles the default java.util.Date.toString() format) - formatter = (java.text.DateFormat)formatters.get(null); + formatter = formatters != null ? (java.text.DateFormat)formatters.get(null) : null; value = formatter.parse(propertyAsString); } } |
From: Chad B. <cwb...@us...> - 2008-08-29 20:27:03
|
User: cwbrandon Date: 08/08/29 13:27:14 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils FormPopulator.java.vsl Log: don't allow null to be set on primitives Revision Changes Path 1.14 +5 -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.13 retrieving revision 1.14 diff -u -w -r1.13 -r1.14 --- FormPopulator.java.vsl 7 Jul 2008 18:21:49 -0000 1.13 +++ FormPopulator.java.vsl 29 Aug 2008 20:27:14 -0000 1.14 @@ -235,8 +235,12 @@ value = org.apache.commons.beanutils.ConvertUtils.convert(propertyAsString, descriptor.getPropertyType()); } } + // - don't attempt to set null on primitive fields + if (value != null || !descriptor.getPropertyType().isPrimitive()) + { org.apache.commons.beanutils.PropertyUtils.setProperty(form, name, value); } + } else { value = property; |