Struts: Indexed Properties in an Iterate tage?

Discussions

Web tier: servlets, JSP, Web frameworks: Struts: Indexed Properties in an Iterate tage?

  1. Struts: Indexed Properties in an Iterate tage? (3 messages)

    Hi all,

    There's an array with variable length, I want to use it in order to create some <html:text> tags with indexed property, so I use a tag like what follows:
    <logic:iterate name="theArray" id="element" indexId="index">

    I tried following tag to create text input fields
    <html:text property="theArray[index].propertyName" />
    but an IllegalArgumentException occurs when I run the application.

    What is the correct <html:text> with an indexed property to be nested in the <logic:iterate> tag?

    Thanks
    Majid Makki
  2. Hi,

    the iterate tag stores the current iteration element in a page context variable with the name "id". So you can use it directly:

    <logic:iterate name="theArray" id="element">
       <html:text name="element" property="propertyName"/>
    </logic:iterate>

    Hope that helps,

    René Zanner
  3. A solution[ Go to top ]

    If you need to get the value, you try to document.form[0][fieldName]
  4. Hi,

    try the following:
    <html:text property='<%= "theArray[" + index + "].propertyName" %>'/>

    or if you want to avoid the pain with the notation
    user struts-el:
    <html:text property="theArray[${index}].propertyName"/>

    you can read mor about indexed properties at http://struts.apache.org/faqs/indexedprops.html

    hope this helps,
    Andreas.