Hi,

I proposed a change to Struts form tags (e.g. <html:text>, <html:hidden>,
<html:checkbox> etc) a few days ago so that they would generate appropriate
name attributes to automatically populate collections when embedded in the
<logic:iterate> tag.

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg05231.html>

What I proposed was that tags such as the above would check if they are
embeded in an <logic:iterate> tag and generate a name attribute
appropriately. I changed the <html:text>, <html:hidden>, <html:checkbox>
tags so that instead of setting the name property to this.property they used
the following method to determine the name (and it worked OK).

    private String decideName() {
      // Check if this Tag is embedded in an Iterator Tag
      Tag tag = findAncestorWithClass(this, IterateTag.class);

      // No iterator, use the property as the name
      if (tag == null)
        return this.property;

      IterateTag iterator = (IterateTag)tag;
      int index = iterator.getLengthCount()-1;

      return iterator.getProperty()+"["+index+"]."+this.property;
    }

(Addtionally the <logic:iterate> tag needs to be changed to have a
getLengthCount() method included).

Perhaps this is not a good idea causing too many problems with, for example,
compatibility or scope but I would appreciate some feed back. I'm sure if
this change is not suitable as it stands there are alternatives which would
make it work such as an new attribute which would cause this to be generated
or alternatively if you could provide a default method which sets the name
to this.property, but could be overriden so that the tags could be
sub-classed.

Any feed back would be appreciated.

Niall

This proposal would take Struts jsp such as:
    <logic:iterate id="list" name="formExample" property="beanArray">
       <tr><td><html:hidden name="list" property="code"/></td>
           <td><html:checkbox name="list" property="select"/></td>
           <td><html:text name="list" property="desc"/></td>
       </tr>
    </logic:iterate>
Would generate fields such as:
                <input type="hidden" name="beanArray[0].code" value=".."/>
                <input type="checkbox" name="beanArray[0].select"/>
                <input type="text" name="beanArray[0].desc" value=".."/>
Causing Struts to automatically populate a collection of beans using:
                        formExample.getBeanArray(0).setCode(xxxxx);
                        formExample.getBeanArray(0).setDesc(xxxxx);
                        formExample.getBeanArray(0).setSelect(xxxxx);

Previous Related Threads:
form question
<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg05210.html>

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg05216.html>

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg05231.html>
logic:iterate and form controls, revisited
<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg02128.html>

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg04316.html>

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg02145.html>
<logic:iterate> and form input fields

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg01662.html>

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg01646.html>

<http://www.mail-archive.com/struts-user@jakarta.apache.org/msg01417.html>

winmail.dat

Reply via email to