On Thu, May 23, 2002 at 05:10:19PM -0400, Boyalla, Raveendra wrote:
> I have variable no of rows and variable no of columns of text boxes.
> 
> So ActionForm should be able to store them in Arrays in Array .
> 
> I can not use a simple Array in ActionForm.
> It should be an Arrays in Array.
> Does ActionForm grabs and populate text boxes from Arrays-in-Array type of
> Objects?

Yes, you can do it with Struts by combining indexed and nested
properties on your form.  No additional components are required.  I
worked this code out just now:

----in your form class----
protected List gridRows;

public void reset(ActionMapping mapping, HttpServletRequest request) {
    gridRows=new ArrayList(10);
    for(int i=0; i<10; i++) {
        gridRows.add(new Row(7));
    }
}

/** Returns the list of Row objects */
public List getGridRows() {
    return gridRows;
}

/** Sets the new list of Row objects */
public void setGridRows(List newGridRows) {
    gridRows=newGridRows;
}

/** A class with a single property that the Struts ActionServlet can populate */
public static class Row {
    protected List items;
        public Row(int length) {
        items=new ArrayList(length);
        for(int i=0; i<length; i++) {
            items.add("");
        }
    }

    public List getItems() {
        return items;
    }

    public void setItems(List newItems) {
        items=newItems;
    }

    public int size() {
        return items.size();
    }
}
-------------------

----In your JSP----
<html:form action="/categoryEditScreen" method="get">
  <bean:define id="form" name="categoryForm" type="CategoryForm"/>
  <%
    int height=form.getGridRows().size();
    int width=((CategoryForm.Row)form.getGridRows().get(0)).size();
  %>
  <table>
    <% for(int y=0; y<height; y++) { %>
      <tr>
        <% for(int x=0; x<width; x++) { %>
          <td><html:text property='<%= "gridRows["+y+"].items["+x+"]" %>'/></td>
        <% } %>
      </tr>
    <% } %>
  </table>
</html:form>
-------------------

Of course, you could use logic:iterate tags if you prefer, but I've
been running into problems on Tomcat 4.0 with Java 1.4 on Solaris,
where the JSP won't compile if there are many JSP custom tags.  Taking
out the iterate tags solves the compilation problem for us without
killing too much readability.

Let me know if you get it working on your end.

-- 
Jonathan Fuerth - SQL Power Group Inc.
(416)218-5551 (Toronto); 1-866-SQL-POWR (Toll-Free)
Unleash the Power of your Corporate Data - http://www.sqlpower.ca/

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to