struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sashi Ravipati" <>
Subject Re: adding / creating new collection elements in a form
Date Fri, 06 Jun 2003 13:07:20 GMT
I have a javascript wich woks, u can give it a try, replace the html
tags with Struts Html tags, it should work

<title>adding table rows with input elements
<script type="text/javascript">

var TDCount = 0;

function insertTableRow(id)
var table = document.getElementById(id);

// get number of current rows
var rowItems = table.getElementsByTagName("tr");
var rowCount = rowItems.length;

// insert the new row
var newRow = table.insertRow(rowCount);

// get count of cells for the last row (so we know how many to insert)
var cellItems = rowItems[rowCount-1].getElementsByTagName("td");
var cellCount = cellItems.length;

// loop over the children of the last set of cells
for (i=0; i<cellCount; i++)
  // insert an analagous cell
  var cell = newRow.insertCell(i);
  // get the children of each cell
  var kids = cellItems[i].childNodes;

  for (j=0; j<kids.length; j++)
    var newChild = kids[j].cloneNode(true);

    // copy data into this cell

<form name="form1" method="GET" action="">
<table width="75%" border="1" id="mytable">
    <td><input name="BEGINDATE" type="text" id="CPUtype"></td>
    <td><input name="ENDDATE" type="text" id="CPUSerial1"></td>
<input type="button" name="addRow" value="Add Row"
<a href="javascript:insertTableRow('mytable')">Add Row</a></


>>> 06/06/03 06:38PM >>>
I've not been able to find a solution to this within the mailing
list.  But I would like to the following.

I have a page with a collection of fields which are populated by
a form (via it's collection).  I also have a button which would
allow the addition of a new row. (hopefully)

  Name  Descrip
[ xy ][ foo   ]
[ ab ][ bar   ]


(1) I would like to have the add button add a new pair of text
input fields each time it is clicked. (2) I would like it if
clicking add did not make a request to the server this being the
case it suggests some kind of client side javascript adding the
new fields.

The problems of course with this are the following.

(1) client side code won't be able to utilise the struts tags
     and as such I won't know what values to set the appropriate
     input text element attributes to.
(2) It is highly likely that even if I solved problem (1) that
     it would result in a IndexOutOfBounds exception, or just not
     bother with the properties from the new fields.

Has anyone else solved this?  Does struts have a mechanism for
dealing with this?  I'm fully aware of nested/logic tags but
if they are the way I can't see how.

Suggestions would be appreciated, Thanks!


To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message