How to Set an Array Property in an ATG Form

Cool Blue Hive on Flickr
(Photo: Cool Blue Hive by jurvetson)

In the Setting Property Values in Forms section of the ATG Page Developer’s Guide there are two examples for setting values of array properties in forms.

  1. Grouped Checkboxes
  2. Multiple-Selection List Box

Both examples are for a simple form.  But what if you are generating a form using a ForEach droplet and want to set an array property in each iteration of the loop.  Fortunately it turns out to be relatively easy.

Hidden or Text Inputs


  
    
  

Select Inputs


  
    
     foo
     bar
    
  

By the way if you try to set the array element directly using the param:index notation as in the following example it will not work.


  
    
     foo
     bar
    
  

When submitting the above form you will get this exception.

atg.droplet.DropletException:
  Can't set an element of the array property without a set  (int index, Object value) method.

The exception message is a red herring, there is no way you can set the element of an array property no matter what kind of set method you create.  Trust me, I spent many hours delving into the ATG code to verify this. 🙂


One thought on “How to Set an Array Property in an ATG Form

  1. I tried with the following getter/setter in formhandler and it works.

    public String[] getHobbies() {
    return hobbies;
    }
    public void setHobbies(int index, Object value){
    this.hobbies[index]=(String)value;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *