You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nathan Coast <na...@levelseas.com> on 2001/07/31 11:22:56 UTC

indexed properties problems ArrayIndexOutOfBoundsException

Hi,

I've followed various threads (Long Story Short etc) about Dave Hays index
tags enhancement and after much hair tearing!

The suggested code for the form bean is:

   private ArrayList parameterList = new ArrayList();

   public ArrayList getParameterList()
   {
      return(this.parameterList);
   }

   public void setParameterList(ArrayList parameterList)
   {
      this.parameterList = parameterList;
   }

   public Parameter getParameter(int index)
   {
	System.out.println(index);
        if (idx > parameterList.size()-1)
        {
            parameterList.add(index,new Parameter ());
        }
        return (Parameter) parameterList.get(index);   
	}

The problem I'm getting is that struts is calling the getParameter(index)
method out of sequence e.g.

index=5
index=4
index=17
index=17
index=3
index=7
index=16
index=15
index=2
index=14
index=10
index=1
index=0
etc......

and so the calls to "add" and "get" on the ArrayList result in
ArrayIndexOutOfBoundsException rather than building up the values.

This problem would go away if I used session scope form beans but I'd rather
not do that.

Has anyone else seen this problem / found a neat solution?

Cheers Nathan


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************