commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoffrey Arnold <geoff...@geoffreyarnold.com>
Subject [Jelly] Tag attributes corresponding to arrays
Date Wed, 05 May 2004 19:52:44 GMT
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.

Mime
View raw message