You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Natalie Rassmann <na...@lmco.com> on 2003/07/21 20:44:55 UTC

Building Dynamic Tables with DyanValidatorForms

Can anyone help?  I have been trying to build a dynamic table using a
DynaValidatorForm as my form.  I am having trouble.   I have javascript
code to dyanmically add rows to the table but when I hit the submit
button, the form does not contain these new rows.  I don't know how to
get these new rows into the form in the jsp file.  Can anyone help
explain how this might happen?

Here is a snipet of my code:


    <form-bean name="reviewRecordForm"
type="prtr.forms.ReviewRecordForm" dynamic="true">
       <form-property name="reviewRecId" type="java.lang.Long"/>
       <form-property name="projectRevId" type="java.lang.Long"/>
       <form-property name="recordType" type="java.lang.String"/>
       <form-property name="date" type="java.lang.String"/>
       <form-property name="trNumber" type="java.lang.String"/>
       <form-property name="scNumber" type="java.lang.String"/>
       <form-property name="crNumber" type="java.lang.String"/>
       <form-property name="reviewTitle" type="java.lang.String"/>
       <form-property name="productTitle" type="java.lang.String"/>
       <form-property name="productNumber" type="java.lang.String"/>
       <form-property name="module" type="java.lang.String"/>
       <form-property name="sizes"
type="prtr.data.DTO.TextValueBean[]"/>
       <form-property name="disposition"
type="prtr.data.DTO.OptionsBean"/>
       <form-property name="times"
type="prtr.data.DTO.MeetingTimesBean[]"/>
       <form-property name="meetingTimes"
type="prtr.data.DTO.MeetingTimesDTO[]"/>
       <form-property name="timesList" type="java.util.ArrayList"/>
       <form-property name="id" type="java.lang.String[]"/>
       <form-property name="time" type="java.lang.String[]"/>
       <form-property name="meetingAttendees"
type="prtr.data.DTO.MeetingAttendeesDTO[]"/>
</form-bean>

jsp code:

<!--  Meeting Table -->

<table width="75%" border="1" id="meetingTimesTable">
   <tr>
      <th valign="top" colspan="2" align="center" bgcolor="#FFFFCC"
nowrap>Meetings</th>
   </tr>


   <c:forEach var="times" items="${reviewRecordForm.map.times}">

   <tr>

      <td>Meeting
         <html:text indexed="true" name="times" property="id"/>
      </td>
      <td>Elapsed Time
         <html:text indexed="true" name="times" property="time"/>
      </td>

   </tr>

   </c:forEach>

</table>



<br>
<input type="button" name="addRow" value="Add Row"
onClick="insertTableRow('meetingTimesTable')">


javascript code:
<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
    cell.appendChild(newChild);
  }
}
}
</script>


action code:

   //debug
        MeetingTimesBean[] newList =
(MeetingTimesBean[])reviewRecordForm.get("times");
        System.out.println("newlist size is " + newList.length);
        java.util.ArrayList newListAsArrayList = new
java.util.ArrayList(java.util.Arrays.asList((MeetingTimesBean[])reviewRecordForm.get("times")));

        System.out.println("newList is " + newListAsArrayList);

When I print this, I always get only one line (the first row which I put
in there as a default).

If anyone can help I would appreciate it.  I have been working on this
several days and I am stumpped.

Natalie


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Building Dynamic Tables with DyanValidatorForms

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I don't recognise the javascript functions table.insertRow() and 
row.insertCell(), but I have written javascript to manipulate the html 
dom and I had problems copying stuff, i.e. it just wouldn't. But I never 
got the copied stuff to appear on the page like you have. I found I 
could only create new nodes and get the text from one place and put it 
in the new nodes.

I expect that your browser is just not creating the form elements 
properly - you could write a simple debug test in the onsubmit event to 
loop thro the form to see what elements it really has.  I bet your new 
elements don't get that far.

Adam

Natalie Rassmann wrote:
> Can anyone help?  I have been trying to build a dynamic table using a
> DynaValidatorForm as my form.  I am having trouble.   I have javascript
> code to dyanmically add rows to the table but when I hit the submit
> button, the form does not contain these new rows.  I don't know how to
> get these new rows into the form in the jsp file.  Can anyone help
> explain how this might happen?
> 
> Here is a snipet of my code:
> 
> 
>     <form-bean name="reviewRecordForm"
> type="prtr.forms.ReviewRecordForm" dynamic="true">
>        <form-property name="reviewRecId" type="java.lang.Long"/>
>        <form-property name="projectRevId" type="java.lang.Long"/>
>        <form-property name="recordType" type="java.lang.String"/>
>        <form-property name="date" type="java.lang.String"/>
>        <form-property name="trNumber" type="java.lang.String"/>
>        <form-property name="scNumber" type="java.lang.String"/>
>        <form-property name="crNumber" type="java.lang.String"/>
>        <form-property name="reviewTitle" type="java.lang.String"/>
>        <form-property name="productTitle" type="java.lang.String"/>
>        <form-property name="productNumber" type="java.lang.String"/>
>        <form-property name="module" type="java.lang.String"/>
>        <form-property name="sizes"
> type="prtr.data.DTO.TextValueBean[]"/>
>        <form-property name="disposition"
> type="prtr.data.DTO.OptionsBean"/>
>        <form-property name="times"
> type="prtr.data.DTO.MeetingTimesBean[]"/>
>        <form-property name="meetingTimes"
> type="prtr.data.DTO.MeetingTimesDTO[]"/>
>        <form-property name="timesList" type="java.util.ArrayList"/>
>        <form-property name="id" type="java.lang.String[]"/>
>        <form-property name="time" type="java.lang.String[]"/>
>        <form-property name="meetingAttendees"
> type="prtr.data.DTO.MeetingAttendeesDTO[]"/>
> </form-bean>
> 
> jsp code:
> 
> <!--  Meeting Table -->
> 
> <table width="75%" border="1" id="meetingTimesTable">
>    <tr>
>       <th valign="top" colspan="2" align="center" bgcolor="#FFFFCC"
> nowrap>Meetings</th>
>    </tr>
> 
> 
>    <c:forEach var="times" items="${reviewRecordForm.map.times}">
> 
>    <tr>
> 
>       <td>Meeting
>          <html:text indexed="true" name="times" property="id"/>
>       </td>
>       <td>Elapsed Time
>          <html:text indexed="true" name="times" property="time"/>
>       </td>
> 
>    </tr>
> 
>    </c:forEach>
> 
> </table>
> 
> 
> 
> <br>
> <input type="button" name="addRow" value="Add Row"
> onClick="insertTableRow('meetingTimesTable')">
> 
> 
> javascript code:
> <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
>     cell.appendChild(newChild);
>   }
> }
> }
> </script>
> 
> 
> action code:
> 
>    //debug
>         MeetingTimesBean[] newList =
> (MeetingTimesBean[])reviewRecordForm.get("times");
>         System.out.println("newlist size is " + newList.length);
>         java.util.ArrayList newListAsArrayList = new
> java.util.ArrayList(java.util.Arrays.asList((MeetingTimesBean[])reviewRecordForm.get("times")));
> 
>         System.out.println("newList is " + newListAsArrayList);
> 
> When I print this, I always get only one line (the first row which I put
> in there as a default).
> 
> If anyone can help I would appreciate it.  I have been working on this
> several days and I am stumpped.
> 
> Natalie
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org