commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: [Jelly] Tag attributes corresponding to arrays
Date Wed, 05 May 2004 21:27:19 GMT
hmmm...

here's some (disconnected) comments:

the use of beanutils in jelly is one of the big issues that needs to be  
resolved (or at least thought about). we're going to have to release a  
new version of beanutils very soon (to solve collections 2.0/3.0  
compatibility issues) and it's possible that the new beanified stuff  
might be useful in jelly.

i think that you might be able to achieve the same result by  
registering a custom convertor. this is currently a little icky to do  
but it would probably be possible to add some (probably core) tags that  
would allow the conversions to be customized. i'm not sure whether  
that'd be a good idea or not.

in some ways, using the specialized http copy makes some sense because  
jelly's stringy like html but the implementation is less sophisticated.  
would altering one to the other cause loads of stuff to break?

comments welcome but probably paul or dIon are the people who need to  
jump in...

- robert

On 5 May 2004, at 20:52, Geoffrey Arnold wrote:

> Hi All.
>
> I have been testing Jelly and JellySwing extensively and am encouraged  
> by their potential as an Java alternative to Windows Forms .NET.
>
> I recently came across a problem with tag attributes which correspond  
> to arrays in JavaBeans.  For example, given the following bean:
>
> public class SampleBean {
>   public String[] theArray;
>   ...
>   public String[] getTheArray() {
>     return this.theArray;
>   }
>   public void setTheArray(String[] anArray) {
>     this.theArray = anArray;
>   }
> }
>
> ... I hoped to be able to set the value of "theArray" using XML  
> similar to the following:
>
> <jelly:useBean var="sampleBean" class="SampleBean" theArray="element1,  
> element2, element3"/>
>
> However, instead of converting the attribute value to an array of  
> three elements (ie. new String[3] {"element1", "element2",  
> "element3"}) as intended, the result was an array with one element  
> consisting of the entire attribute value (ie. new String[1]  
> {"element1, element2, element3"}).  After some investigation I was  
> able to determine that this behavior is caused by the use of the  
> methods BeanUtils.setProperty() and BeanUtils.populate() which are  
> "...customized for extracting String-based request parameters from an  
> HTTP request"  
> (http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/ 
> beanutils/BeanUtils.html#populate(java.lang.Object,%20java.util.Map)).  
>  I was able to produce the desired behavior by changing all references  
> to these methods to the alternative functions BeanUtils.copyProperty()  
> and BeanUtils.copyProperties(), respectively, which properly convert  
> the attribute values.
>
> Attached is a diff for the offending classes contained in the Jelly  
> and JellySwing tag libraries.  Also note that a quick search revealed  
> classes in other Jelly tag libraries which will require changes:
>
>  jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant/AntTag.java
>   
> jelly-tags/ant/src/java/org/apache/commons/jelly/tags/ant/ 
> FileScannerTag.java
>   
> jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/ 
> BeanTag.java
>   
> jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/ 
> SetTag.java
>   
> jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/ 
> LayoutTagSupport.java
>
> Hope this helps.
> Geoff.
> Index:  
> jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ 
> ComponentTag.java
> ===================================================================
> RCS file:  
> /home/cvspublic/jakarta-commons/jelly/jelly-tags/swing/src/java/org/ 
> apache/commons/jelly/tags/swing/ComponentTag.java,v
> retrieving revision 1.17
> diff -u -r1.17 ComponentTag.java
> ---  
> jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ 
> ComponentTag.java	25 Feb 2004 01:31:56 -0000	1.17
> +++  
> jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ 
> ComponentTag.java	5 May 2004 18:04:14 -0000
> @@ -59,7 +59,7 @@
>
>      /** the factory of widgets */
>      private Factory factory;
> -
> +
>      public ComponentTag() {
>      }
>
> @@ -82,7 +82,7 @@
>          if ( component != null ) {
>              // lets just try set the 'action' property
>              try {
> -                BeanUtils.setProperty( component, "action", action );
> +                BeanUtils.copyProperty( component, "action", action );
>              } catch (IllegalAccessException e) {
>                  throw new JellyTagException(e);
>              } catch (InvocationTargetException e) {
> @@ -99,7 +99,7 @@
>          if ( component != null ) {
>              // lets just try set the 'font' property
>              try {
> -                BeanUtils.setProperty( component, "font", font );
> +                BeanUtils.copyProperty( component, "font", font );
>              }
>              catch (IllegalAccessException e) {
>                  throw new JellyTagException(e);
> @@ -118,7 +118,7 @@
>          if ( component != null ) {
>              try {
>                  // lets just try set the 'border' property
> -                BeanUtils.setProperty( component, "border", border );
> +                BeanUtils.copyProperty( component, "border", border );
>              }
>              catch (IllegalAccessException e) {
>                  throw new JellyTagException(e);
> @@ -142,7 +142,7 @@
>
>              try {
>                  // lets just try set the 'layout' property
> -                BeanUtils.setProperty( component, "layout", layout );
> +                BeanUtils.copyProperty( component, "layout", layout );
>              }
>              catch (IllegalAccessException e) {
>                  throw new JellyTagException(e);
> @@ -383,7 +383,7 @@
>                  }
>                  else {
>                      try {
> -                        BeanUtils.setProperty(component, name, value);
> +                        BeanUtils.copyProperty(component, name,  
> value);
>                      } catch (IllegalAccessException e) {
>                          throw new JellyTagException(e);
>                      } catch (InvocationTargetException e) {
> @@ -393,7 +393,7 @@
>              }
>              else {
>                  try {
> -                    BeanUtils.setProperty(bean, name, value);
> +                    BeanUtils.copyProperty(bean, name, value);
>                  } catch (IllegalAccessException e) {
>                      throw new JellyTagException(e);
>                  } catch (InvocationTargetException e) {
> Index:  
> jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ 
> ConstraintTag.java
> ===================================================================
> RCS file:  
> /home/cvspublic/jakarta-commons/jelly/jelly-tags/swing/src/java/org/ 
> apache/commons/jelly/tags/swing/ConstraintTag.java,v
> retrieving revision 1.9
> diff -u -r1.9 ConstraintTag.java
> ---  
> jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ 
> ConstraintTag.java	1 Mar 2004 12:35:18 -0000	1.9
> +++  
> jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ 
> ConstraintTag.java	5 May 2004 18:04:14 -0000
> @@ -98,7 +98,7 @@
>  		} else {
>
>              try {
> -              BeanUtils.setProperty( bean, name, value );
> +              BeanUtils.copyProperty( bean, name, value );
>              } catch (IllegalAccessException e) {
>                  throw new JellyTagException(e.toString());
>              } catch (InvocationTargetException e) {
> Index:  
> src/java/org/apache/commons/jelly/tags/core/SetPropertiesTag.java
> ===================================================================
> RCS file:  
> /home/cvspublic/jakarta-commons/jelly/src/java/org/apache/commons/ 
> jelly/tags/core/SetPropertiesTag.java,v
> retrieving revision 1.7
> diff -u -r1.7 SetPropertiesTag.java
> ---  
> src/java/org/apache/commons/jelly/tags/core/SetPropertiesTag.java	24  
> Feb 2004 14:10:38 -0000	1.7
> +++  
> src/java/org/apache/commons/jelly/tags/core/SetPropertiesTag.java	5  
> May 2004 18:04:15 -0000
> @@ -80,7 +80,7 @@
>       */
>      protected void setBeanProperties(Object bean, Map attributes)  
> throws JellyTagException {
>          try {
> -            BeanUtils.populate(bean, attributes);
> +            BeanUtils.copyProperties(bean, attributes);
>          } catch (IllegalAccessException e) {
>              throw new JellyTagException("could not set the properties  
> on a bean",e);
>          } catch (InvocationTargetException e) {
> Index: src/java/org/apache/commons/jelly/tags/core/SetTag.java
> ===================================================================
> RCS file:  
> /home/cvspublic/jakarta-commons/jelly/src/java/org/apache/commons/ 
> jelly/tags/core/SetTag.java,v
> retrieving revision 1.17
> diff -u -r1.17 SetTag.java
> --- src/java/org/apache/commons/jelly/tags/core/SetTag.java	24 Feb  
> 2004 14:10:38 -0000	1.17
> +++ src/java/org/apache/commons/jelly/tags/core/SetTag.java	5 May 2004  
> 18:04:15 -0000
> @@ -172,7 +172,7 @@
>                  map.put( property, value );
>              }
>              else {
> -                BeanUtils.setProperty( target, property, value );
> +                BeanUtils.copyProperty( target, property, value );
>              }
>          } catch (InvocationTargetException e) {
>              log.error( "Failed to set the property: " + property + "  
> on bean: " + target + " to value: " + value + " due to exception: " +  
> e, e );
> Index: src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java
> ===================================================================
> RCS file:  
> /home/cvspublic/jakarta-commons/jelly/src/java/org/apache/commons/ 
> jelly/tags/core/UseBeanTag.java,v
> retrieving revision 1.14
> diff -u -r1.14 UseBeanTag.java
> --- src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java	24 Feb  
> 2004 14:10:38 -0000	1.14
> +++ src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java	5 May  
> 2004 18:04:15 -0000
> @@ -166,7 +166,7 @@
>       */
>      protected void setBeanProperties(Object bean, Map attributes)  
> throws JellyTagException {
>          try {
> -            BeanUtils.populate(bean, attributes);
> +            BeanUtils.copyProperties(bean, attributes);
>          } catch (IllegalAccessException e) {
>              throw new JellyTagException("could not set the properties  
> of the bean",e);
>          } catch (InvocationTargetException e) {
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message