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 |