You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Geoffrey Arnold <ge...@geoffreyarnold.com> on 2004/05/05 20:16:11 UTC

[Jelly] Tag attributes corresponding to arrays

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.

Re: [Jelly] Tag attributes corresponding to arrays

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
our emails seem to have passed in transit :)

On 5 May 2004, at 22:38, Paul Libbrecht wrote:

> THere has been many mentions about Jelly "not converting my string 
> into an array as expected"...
> Same thing happens in j:forEach: people expect the list to be 
> "naturally" separated by some spaces, commas, or whatever...
>
> Everytime I read this I keep being frightened if such a feature would 
> be introduced in Jelly... It would be very very unpredictable (suppose 
> I am using this with the input of a user...).

+1

> In order for such a patch and several others to be applied, I would 
> like to become convinced that one can do this in a way developers 
> expect.

+1

> One way could be to have separators as extra attribute:
> - this would work well for j:forEach
> - it would solve the problem here except that "separator" or 
> "separators" couldn't be a bean-property-name
> Remember, though, that we would need a syntax for such separators, in 
> particular if one wishes to express categorie of characters like 
> "whitespace".

in general, i agree.

i have observed (from betwixt where the comma is the only separator 
that's been requested) that comma separation is the pseudo-standard 
(most common use case). so, a specific solution for this use case may 
well be good enough.

> Anyone else with good ideas ? A global setting impacting BeanUtils ?

there are a number of beanutils related stuff that we could think about 
trying. beanutils has become critical (there are lot of applications 
that require a beanutils release that is compatible with the 
incompatible 2.1 and 3.0 versions of collections very soon) and so the 
beanified version is going to get sorted out now. this means that it'd 
be both an opertunity to look at what jelly needs from beanutils and 
also to reconsider the jelly tag's use of the older, static jelly 
methods.

(i'm going to be busy tomorrow and friday but hopefully i'll be able to 
pick up this thread this weekend...)

- robert


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


Re: [Jelly] Tag attributes corresponding to arrays

Posted by Paul Libbrecht <pa...@activemath.org>.
THere has been many mentions about Jelly "not converting my string into 
an array as expected"...
Same thing happens in j:forEach: people expect the list to be 
"naturally" separated by some spaces, commas, or whatever...

Everytime I read this I keep being frightened if such a feature would 
be introduced in Jelly... It would be very very unpredictable (suppose 
I am using this with the input of a user...).

In order for such a patch and several others to be applied, I would 
like to become convinced that one can do this in a way developers 
expect.

One way could be to have separators as extra attribute:
- this would work well for j:forEach
- it would solve the problem here except that "separator" or 
"separators" couldn't be a bean-property-name
Remember, though, that we would need a syntax for such separators, in 
particular if one wishes to express categorie of characters like 
"whitespace".

Anyone else with good ideas ? A global setting impacting BeanUtils ?

thanks

paul



On 5-May-04, at 20:16 Uhr, 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"/>


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