implement paging to dynamic rows

My requirement is to implement paging  for dynamic rows in the jsp.

in the following code,

createRow() is used to create the dynamic row.

in that i have added following code


                  <table border='0' width="<%=tableWidth%>" cellspacing='1' cellpadding='2' nowrap>
                   <tr>
                        <td>
                              <input type='button' id='Prev' class=input value='<-' onClick='showPrevPage();' style='visibility:hidden'>
                        </td>
                        <td>
                              <input type='button' id='Next' class=input value='->' onClick='showNextPage();' visibility='false' style='visibility:hidden'>
                        </td>
                  </tr>
                  </table>

for two buttons , next and previous.

when page loads in the body onload i will call initializeDynamicContentRows();

when the user is in Add Mode user can enter upto 50 dynamicRows at a time then user clicks next button 1 dynamic row should be displayed.
when the user is in Modify Mode user can enter upto 50 dynamicRows at a time then user clicks next button remaining  dynamic rows should be displayed.

<script>
function initializeDynamicContentRows()
{
      setValues();
      focusField();
}
var partyReferenceEventError                                    = false;
var partyMonetaryEventError                                    = false;
var partyDateEventError                                          = false;
var generalReferenceEventError                              = false;
var generalMonetaryEventError                              = false;
var generalDateEventError                                          = false;
var partyMonetaryCurrencyError                              = false;
var generalMonetaryCurrencyError                        = false;
function setValues()
{
      var defaultPartyReferencesEventsTableObj      = document.getElementById("defaultPartyReferencesEventsTable");
      var defaultPartyMonetaryEventsTableObj            = document.getElementById("defaultPartyMonetaryEventsTable");
      var defaultPartyDateEventsTableObj                  = document.getElementById("defaultPartyDateEventsTable");

      var partyReferencesEventsTableObj                        = document.getElementById("partyReferencesEventsTable");
      var partyMonetaryEventsTableObj                        = document.getElementById("partyMonetaryEventsTable");
      var partyDateEventsTableObj                                    = document.getElementById("partyDateEventsTable");

      var generalReferencesEventsTableObj                  = document.getElementById("generalPartyReferencesEventsTable");
      var generalMonetaryEventsTableObj                        = document.getElementById("generalMonetaryEventsTable");
      var generalDateEventsTableObj                              = document.getElementById("generalDateEventsTable");

      var referenceEventsCounter                                    = 0;
      var monetaryEventsCounter                                    = 0;
      var dateEventsCounter                                                = 0;
      var currentIndex                                                            = 0;
<%
      boolean isSuggestedFlag                  = true;
      ArrayList referenceEventPartsList= null;
      if(eventReferencesList!=null && eventReferencesList.size()>0)
      {
            for(int i=0;i<eventReferencesList.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)eventReferencesList.get(i);
                  if(!shipmentEvent.isSuggested.equals("Y"))
                  {
                        isSuggestedFlag = false;
                        continue;
                  }
                  if(!shipmentEvent.isValidEvent)
                        out.println("partyReferenceEventError = true;");
%>
                  createRow(defaultPartyReferencesEventsTableObj.getAttribute("id"));
                  currentIndex = (defaultPartyReferencesEventsTableObj.getAttribute("idcounter")*1-1);
                  document.getElementById("referenceEventPartyType"+currentIndex).value = "<%=shipmentEvent.mappedType%>";
                  document.getElementById("referenceEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("referenceEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("referenceEventRefId"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("referenceEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("referenceShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("referenceEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
                  document.getElementById("referenceEventCustomer"+currentIndex).value = "<%=shipmentEvent.eventCustomer%>";
                  transformSelectField(document.getElementById("referenceEventPartyType"+currentIndex));

                  var childTableObj = document.getElementById("child"+defaultPartyReferencesEventsTableObj.getAttribute("id")+currentIndex);
<%
                  referenceEventPartsList = shipmentEvent.getEventPartsList();
                  if(referenceEventPartsList!=null)
                  {
                        EventPartsModel eventPartsModel = null;
                        for(int j=0;j<referenceEventPartsList.size();j++)
                        {
                              eventPartsModel = (EventPartsModel)referenceEventPartsList.get(j);
%>
                              childTableIndex = childTableObj.getAttribute("idcounter")*1-1;
                              document.getElementById("partId"+defaultPartyReferencesEventsTableObj.getAttribute("id")+currentIndex+childTableIndex).value = "<%=eventPartsModel.partId%>";
                              document.getElementById("partQty"+defaultPartyReferencesEventsTableObj.getAttribute("id")+currentIndex+childTableIndex).value = "<%=eventPartsModel.quantity%>";
<%
                              if(j<referenceEventPartsList.size()-1)
                              {
                                    out.println("createSubRow(defaultPartyReferencesEventsTableObj.getAttribute('id'),currentIndex);");
                              }
                        }
                  }
            }
            if(!isSuggestedFlag)
                  out.println("referenceEventsCounter++;");
            out.println("partyReferencesEventsTableObj.setAttribute('idcounter',defaultPartyReferencesEventsTableObj.getAttribute('idcounter'));");
            //For IsSuggested  = "N"
            for(int i=0;i<eventReferencesList.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)eventReferencesList.get(i);
                  if(!shipmentEvent.isSuggested.equals("N") || shipmentEvent.eventValue1==null || shipmentEvent.eventValue1.length()==0)
                        continue;
                  if(!shipmentEvent.isValidEvent)
                        out.println("partyReferenceEventError = true;");
%>
                  createRow(partyReferencesEventsTableObj.getAttribute("id"));
                  currentIndex = (partyReferencesEventsTableObj.getAttribute("idcounter")*1-1);
                  document.getElementById("referenceEventPartyType"+currentIndex).value = "<%=shipmentEvent.mappedType%>";
                  document.getElementById("referenceEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("referenceEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("referenceEventRefId"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("referenceEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("referenceShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("referenceEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
                  document.getElementById("referenceEventCustomer"+currentIndex).value = "<%=shipmentEvent.eventCustomer%>";
                  var childTableObj = document.getElementById("child"+partyReferencesEventsTableObj.getAttribute("id")+currentIndex);
<%
                  referenceEventPartsList = shipmentEvent.getEventPartsList();
                  if(referenceEventPartsList!=null)
                  {
                        EventPartsModel eventPartsModel = null;
                        for(int j=0;j<referenceEventPartsList.size();j++)
                        {
                              eventPartsModel = (EventPartsModel)referenceEventPartsList.get(j);
%>
                              childTableIndex = childTableObj.getAttribute("idcounter")*1-1;
                              document.getElementById("partId"+partyReferencesEventsTableObj.getAttribute("id")+currentIndex+childTableIndex).value = "<%=eventPartsModel.partId%>";
                              document.getElementById("partQty"+partyReferencesEventsTableObj.getAttribute("id")+currentIndex+childTableIndex).value = "<%=eventPartsModel.quantity%>";
<%
                              if(j<referenceEventPartsList.size()-1)
                              {
                                    out.println("createSubRow(partyReferencesEventsTableObj.getAttribute('id'),currentIndex);");
                              }
                        }
                  }
            }
      }
      isSuggestedFlag                  = true;
      if(monetaryEventsList!=null && monetaryEventsList.size()>0)
      {
            for(int i=0;i<monetaryEventsList.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)monetaryEventsList.get(i);
                  if(!shipmentEvent.isSuggested.equals("Y"))
                  {
                        isSuggestedFlag = false;
                        continue;
                  }
                  if(!shipmentEvent.isValidEvent)
                        out.println("partyMonetaryEventError = true;");
                  if(!shipmentEvent.isValidCurrency)
                        out.println("partyMonetaryCurrencyError = true;");
%>
                  createDynamicContentRow(defaultPartyMonetaryEventsTableObj.getAttribute("id"));
                  currentIndex = (defaultPartyMonetaryEventsTableObj.getAttribute("idcounter")*1-1);
                  document.getElementById("monetaryEventPartyType"+currentIndex).value = "<%=shipmentEvent.mappedType%>";
                  document.getElementById("monetaryEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("monetaryEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("monetaryEventAmount"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("monetaryEventCurrency"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue2)%>";
                  document.getElementById("monetaryEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("monetaryShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("monetaryEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
                  document.getElementById("monetaryEventCustomer"+currentIndex).value = "<%=shipmentEvent.eventCustomer%>";
                  transformSelectField(document.getElementById("monetaryEventPartyType"+currentIndex));
<%
            }
            if(!isSuggestedFlag)
                  out.println("monetaryEventsCounter++;");
            //For IsSuggested  = "N"
            out.println("partyMonetaryEventsTableObj.setAttribute('idcounter',defaultPartyMonetaryEventsTableObj.getAttribute('idcounter'));");
            for(int i=0;i<monetaryEventsList.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)monetaryEventsList.get(i);
                  if(!shipmentEvent.isSuggested.equals("N") || shipmentEvent.eventValue1==null || shipmentEvent.eventValue1.length()==0 || shipmentEvent.eventValue2==null || shipmentEvent.eventValue2.length()==0)
                        continue;
                  if(!shipmentEvent.isValidEvent)
                        out.println("partyMonetaryEventError = true;");
                  if(!shipmentEvent.isValidCurrency)
                        out.println("partyMonetaryCurrencyError = true;");
%>
                  createDynamicContentRow(defaultPartyMonetaryEventsTableObj.getAttribute("id"));
                  currentIndex = (defaultPartyMonetaryEventsTableObj.getAttribute("idcounter")*1-1);
                  document.getElementById("monetaryEventPartyType"+currentIndex).value = "<%=shipmentEvent.mappedType%>";
                  document.getElementById("monetaryEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("monetaryEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("monetaryEventAmount"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("monetaryEventCurrency"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue2)%>";
                  document.getElementById("monetaryEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("monetaryShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("monetaryEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
                  document.getElementById("monetaryEventCustomer"+currentIndex).value = "<%=shipmentEvent.eventCustomer%>";
<%
            }
      }
      isSuggestedFlag                  = true;
      if(dateEvents!=null && dateEvents.size()>0)
      {
            for(int i=0;i<dateEvents.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)dateEvents.get(i);
                  if(!shipmentEvent.isSuggested.equals("Y"))
                  {
                        isSuggestedFlag = false;
                        continue;
                  }
                  if(!shipmentEvent.isValidEvent)
                        out.println("partyDateEventError = true;");
%>
                  createDynamicContentRow(defaultPartyDateEventsTable.getAttribute("id"));
                  currentIndex = (defaultPartyDateEventsTable.getAttribute("idcounter")*1-1);
                  document.getElementById("dateEventPartyType"+currentIndex).value = "<%=shipmentEvent.mappedType%>";
                  document.getElementById("dateEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("dateEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("eventDate"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("eventTime"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue2)%>";
                  document.getElementById("dateEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("dateShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("dateEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
                  document.getElementById("dateEventCustomer"+currentIndex).value = "<%=shipmentEvent.eventCustomer%>";
                  transformSelectField(document.getElementById("dateEventPartyType"+currentIndex));
<%
            }
            if(!isSuggestedFlag)
                  out.println("dateEventsCounter++;");
            //For IsSuggested  = "N"
            out.println("partyDateEventsTable.setAttribute('idcounter',defaultPartyDateEventsTable.getAttribute('idcounter'));");
            for(int i=0;i<dateEvents.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)dateEvents.get(i);
                  if(!shipmentEvent.isSuggested.equals("N") || shipmentEvent.eventValue1==null || shipmentEvent.eventValue1.length()==0 || shipmentEvent.eventValue2==null || shipmentEvent.eventValue2.length()==0)
                        continue;
                  if(!shipmentEvent.isValidEvent)
                        out.println("partyDateEventError = true;");
%>
                  createDynamicContentRow(defaultPartyDateEventsTable.getAttribute("id"));
                  currentIndex = (defaultPartyDateEventsTable.getAttribute("idcounter")*1-1);
                  document.getElementById("dateEventPartyType"+currentIndex).value = "<%=shipmentEvent.mappedType%>";
                  document.getElementById("dateEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("dateEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("eventDate"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("eventTime"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue2)%>";
                  document.getElementById("dateEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("dateShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("dateEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
                  document.getElementById("dateEventCustomer"+currentIndex).value = "<%=shipmentEvent.eventCustomer%>";
<%
            }
      }

      //General Events
      if (subTask.equals("nextPage"))
      {
%>
                  createRow(generalReferencesEventsTableObj.getAttribute("id"),true);
                  document.getElementById('Prev').style.visibility='visible';
<%
System.out.println("generalEventReferencesList @@@@ "+ generalEventReferencesList);
      }else if(generalEventReferencesList!=null && generalEventReferencesList.size()>0)
      {
            for(int i=0;i<generalEventReferencesList.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)generalEventReferencesList.get(i);
                  if(!shipmentEvent.isValidEvent)
                        out.println("generalReferenceEventError = true;");
%>
                  createRow(generalReferencesEventsTableObj.getAttribute("id"),true);

                  currentIndex = (generalReferencesEventsTableObj.getAttribute("idcounter")*1-1);
                  document.getElementById("generalReferenceEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("generalReferenceEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("generalReferenceEventRefId"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("generalReferenceEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("generalReferenceShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("generalReferenceEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";

                  var childTableObj = document.getElementById("child"+generalReferencesEventsTableObj.getAttribute("id")+currentIndex);
<%
                  referenceEventPartsList = shipmentEvent.getEventPartsList();
                  if(referenceEventPartsList!=null)
                  {
                        EventPartsModel eventPartsModel = null;
                        for(int j=0;j<referenceEventPartsList.size();j++)
                        {
                              eventPartsModel = (EventPartsModel)referenceEventPartsList.get(j);
%>
                              childTableIndex = childTableObj.getAttribute("idcounter")*1-1;
                              document.getElementById("partId"+generalReferencesEventsTableObj.getAttribute("id")+currentIndex+childTableIndex).value = "<%=eventPartsModel.partId%>";
                              document.getElementById("partQty"+generalReferencesEventsTableObj.getAttribute("id")+currentIndex+childTableIndex).value = "<%=eventPartsModel.quantity%>";
<%
                              if(j<referenceEventPartsList.size()-1)
                              {
                                    out.println("createSubRow(generalReferencesEventsTableObj.getAttribute('id'),currentIndex);");
                              }
                        }
                  }
            }
      }
      if(generalMonetaryEventsList!=null && generalMonetaryEventsList.size()>0)
      {
            for(int i=0;i<generalMonetaryEventsList.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)generalMonetaryEventsList.get(i);
                  if(!shipmentEvent.isValidEvent)
                        out.println("generalMonetaryEventError = true;");
                  if(!shipmentEvent.isValidCurrency)
                        out.println("generalMonetaryCurrencyError = true;");
%>
                  createDynamicContentRow(generalMonetaryEventsTableObj.getAttribute("id"));
                  currentIndex = (generalMonetaryEventsTableObj.getAttribute("idcounter")*1-1);
                  document.getElementById("generalMonetaryEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("generalMonetaryEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("generalMonetaryEventAmount"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("generalMonetaryEventCurrency"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue2)%>";
                  document.getElementById("generalMonetaryEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("generalMonetaryShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("generalMonetaryEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
<%
            }
      }
      if(generalDateEvents!=null && generalDateEvents.size()>0)
      {
            for(int i=0;i<generalDateEvents.size();i++)
            {
                  shipmentEvent = (ShipmentEvent)generalDateEvents.get(i);
                  if(!shipmentEvent.isValidEvent)
                        out.println("generalDateEventError = true;");
%>
                  createDynamicContentRow(generalDateEventsTableObj.getAttribute("id"));
                  currentIndex = (generalDateEventsTableObj.getAttribute("idcounter")*1-1);
                  document.getElementById("generalDateEventCode"+currentIndex).value = "<%=shipmentEvent.eventCode%>";
                  document.getElementById("generalDateEventDescription"+currentIndex).value = "<%=shipmentEvent.eventDescription%>";
                  document.getElementById("generalEventDate"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue1)%>";
                  document.getElementById("generalEventTime"+currentIndex).value = "<%=StringUtility.noNull(shipmentEvent.eventValue2)%>";
                  document.getElementById("generalDateEventNo"+currentIndex).value = "<%=shipmentEvent.eventNo%>";
                  document.getElementById("generalDateShipmentEventNo"+currentIndex).value = "<%=shipmentEvent.shipmentEventNo%>";
                  document.getElementById("generalDateEventIsSuggested"+currentIndex).value = "<%=shipmentEvent.isSuggested%>";
<%
            }
      }
%>
      hideControlButtons(defaultPartyReferencesEventsTableObj.getAttribute("id"));
      controlDynamicContentControlButtons(defaultPartyMonetaryEventsTableObj.getAttribute("id"),null,defaultPartyMonetaryEventsTableObj.getAttribute("idcounter"),true);
      controlDynamicContentControlButtons(defaultPartyDateEventsTableObj.getAttribute("id"),null,defaultPartyDateEventsTableObj.getAttribute("idcounter"),true);
      var houseOperation = document.getElementById("HouseOperation").value;
      if(houseOperation=="houseModify" && '<%=modifyStatus%>' == 'No')
      {
            manageFields(0);
      }      
      else if(houseOperation!="houseAdd" &&  houseOperation!="houseCopy" &&
            houseOperation!="houseModify" )
      {
            manageFields(0);
      }
      else
      {
            if(referenceEventsCounter>0 && (partyReferencesEventsTableObj.getAttribute("idcounter")==1 || (partyReferencesEventsTableObj.getAttribute("idcounter")==defaultPartyReferencesEventsTableObj.getAttribute("idcounter"))))
            {
                  partyReferencesEventsTableObj.setAttribute("idcounter",defaultPartyReferencesEventsTableObj.getAttribute("idcounter"));
                  createRow(partyReferencesEventsTableObj.getAttribute("id"));
            }

            if(monetaryEventsCounter>0 && (partyMonetaryEventsTableObj.getAttribute("idcounter")==1 || (partyMonetaryEventsTableObj.getAttribute("idcounter")==defaultPartyMonetaryEventsTableObj.getAttribute("idcounter"))))
            {
                  partyMonetaryEventsTableObj.setAttribute("idcounter",defaultPartyMonetaryEventsTableObj.getAttribute("idcounter"));
                  createDynamicContentRow(partyMonetaryEventsTableObj.getAttribute("id"));
            }

            if(dateEventsCounter>0 && (partyDateEventsTableObj.getAttribute("idcounter")==1 || (partyDateEventsTableObj.getAttribute("idcounter")==defaultPartyDateEventsTableObj.getAttribute("idcounter"))))
            {
                  partyDateEventsTableObj.setAttribute("idcounter",defaultPartyDateEventsTableObj.getAttribute("idcounter"));
                  createDynamicContentRow(partyDateEventsTableObj.getAttribute("id"));
            }

            if(generalReferencesEventsTableObj.getAttribute("idcounter")==1)
                  createRow(generalReferencesEventsTableObj.getAttribute("id"),true);

            if(generalMonetaryEventsTableObj.getAttribute("idcounter")==1)
                  createDynamicContentRow(generalMonetaryEventsTableObj.getAttribute("id"));
            
            if(generalDateEventsTableObj.getAttribute("idcounter")==1)
                  createDynamicContentRow(generalDateEventsTableObj.getAttribute("id"));
      }
      managePartyEvents();
      handleErrors();
      if(defaultPartyReferencesEventsTableObj.getAttribute("idcounter")==1 && defaultPartyMonetaryEventsTableObj.getAttribute("idcounter")==1 && defaultPartyDateEventsTableObj.getAttribute("idcounter")==1 && partyReferencesEventsTableObj.getAttribute("idcounter")==1 && partyMonetaryEventsTableObj.getAttribute("idcounter")==1 && partyDateEventsTableObj.getAttribute("idcounter")==1)
      {
            document.getElementById("partyEventsDIV").style.display = "none";
      }
      if(generalReferencesEventsTableObj.getAttribute("idcounter")==1 && generalMonetaryEventsTableObj.getAttribute("idcounter")==1 && generalDateEventsTableObj.getAttribute("idcounter")==1)
      {
            document.getElementById("generalEventsDIV").style.display = "none";
      }
}


//added By Sampath Uppula on 9/17/2004
function showNextPage()
{
      url="ETAHouseDocumentController?subTask=nextPage";
      document.forms[0].action=url;
      alert(url);
//      disableForm(new Array("Submit","Search"));
      document.forms[0].submit();
}

function showPrevPage()
{
      url="ETAHouseDocumentController?subTask=prevPage";
      document.forms[0].action=url;
      alert(url);
//      disableForm(new Array("Submit","Search"));
      document.forms[0].submit();
}
//end
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
function createSubRow(parentTableId,idcounter)
{
      var parentTable                  = document.getElementById(parentTableId);
      if(parentTable==null)
            return;
      if(idcounter==null)
            idcounter = parentTable.getAttribute("idcounter");

      var nameString                  = parentTableId+idcounter;
      var childTable                        = document.getElementById("child"+nameString);
      if(childTable==null)
      {
            childTable                        = document.createElement("TABLE");
            childTable.setAttribute("id","child"+nameString);
            childTable.setAttribute("idcounter","1");
            childTable.setAttribute("width","100%");
      }
      var childTableId                  = childTable.getAttribute("id");
      var childTableIdcounter      = childTable.getAttribute("idcounter");

      var childTableBody            = document.createElement("TBODY");
      var childTableRow                   = document.createElement("TR");

      childTableBody.setAttribute("id",""+parentTableId+"Child"+idcounter+"TBody"+childTableIdcounter);
      childTableBody.setAttribute("tableId",childTable.getAttribute("id"));
      var childTableIdcounter      = childTable.getAttribute("idcounter");
      childTableRow.vAlign             = "top";

      var childTableCell                  = null;
      var tdString                              = "";
      if(childTable.getAttribute("idcounter")=="1")
            tdString = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
      else
            tdString = "<input type=button class=input value='<<' onClick='deleteRow(\""+childTableBody.getAttribute("id")+"\",\"addButtonChild"+parentTableId+""+idcounter+"\")'>&nbsp;";

      tdString += "<input parentTableId='"+childTableId+"' onKeyDown='trapDynamicContentRowKeyDown(event);' name='partId"+nameString+"' id='partId"+nameString+childTableIdcounter+"' class=text size=12 maxlength=16 >";
      tdString += "<input type=hidden name='shipmentPartId"+nameString+"' id='shipmentPartId"+nameString+childTableIdcounter+"'>";

      childTableRow.appendChild(createTDWithHTML(tdString));
      childTableRow.appendChild(createTDWithHTML("<input parentTableId='"+childTableId+"' onKeyDown='trapDynamicContentRowKeyDown(event);' onBlur='roundDecimals(this,0);' name='partQty"+nameString+"' id='partQty"+nameString+childTableIdcounter+"' class=text size=4 maxlength=5 >&nbsp;<input name='addButtonChild"+parentTableId+""+idcounter+"' class=input type=button value='>>' onClick='createSubRow(\""+parentTableId+"\",\""+idcounter+"\")'>"));
      childTableBody.appendChild(childTableRow);
      childTable.appendChild(childTableBody);
      childTableIdcounter++;
      childTable.setAttribute("idcounter",childTableIdcounter);
      handleAddButtons("addButtonChild"+parentTableId+""+idcounter);
      return childTable;
}
function handleAddButtons(addButtonName,enableButton)
{
//      alert(addButtonName);
      var addButtonsCollection = document.getElementsByName(addButtonName);
      if(enableButton)
      {
            for(var i=addButtonsCollection.length-1;i>=0;i--)
            {
                  addButtonsCollection[i].style.visibility = 'visible';
                  break;
            }
      }
      else
      {
            for(var i=0;i<addButtonsCollection.length-1;i++)
            {
                  addButtonsCollection[i].style.visibility = 'hidden';
            }
      }
}
function deleteRow(tbodyId,addButtonName)
{
      var tbody = document.getElementById(tbodyId);
      if(document.all)      //IE
            tbody.removeNode(true);
      else      //NS
            document.getElementById(tbody.getAttribute("tableId")).removeChild(tbody);
      handleAddButtons(addButtonName,true);
}
function hideControlButtons(tableId)
{
      var addButtonsCollection            = document.getElementsByName(tableId+"addButton");
      var deleteButtonsCollection      = document.getElementsByName(tableId+"deleteButton");
      for(var i=0;i<addButtonsCollection.length;i++)
      {
            if(addButtonsCollection[i]!=null)
                  addButtonsCollection[i].style.visibility = 'hidden';
      }
      for(var i=0;i<deleteButtonsCollection.length;i++)
      {
            if(deleteButtonsCollection[i]!=null)
                  deleteButtonsCollection[i].style.visibility = 'hidden';
      }
}
function createRow(tableId,generalEventsFlag)
{
      //alert(tableId+"   "+generalEventsFlag);

      var parentTable                  = document.getElementById(tableId);
      var parentTableBody            = document.createElement("TBODY");
      var idcounter                  = parentTable.getAttribute("idcounter");

      var parentTableRow            = document.createElement("TR");
      parentTableRow.vAlign      = "top";

      parentTableBody.setAttribute("id",tableId+"ParentTBody"+idcounter);
      parentTableBody.setAttribute("tableId",parentTable.getAttribute("id"));

      var parentTableCell            = null;
      var tdString = "";
      if(idcounter==null)
            idcounter=="1";

      if(generalEventsFlag!=null)
            generalEventsFlag==true;

      var nameString = "";

      if(generalEventsFlag)
            nameString = "generalReference";
      else
            nameString = "reference";

      if(idcounter=="1")
            tdString = "&nbsp;";
      else
            tdString = "<input class=input type=button name='"+tableId+"deleteButton' id='"+tableId+"deleteButton"+idcounter+"' value='<<' onClick='deleteRow(\""+parentTableBody.getAttribute("id")+"\",\""+tableId+"addButton\")'>";
      tdString += "<input type=hidden name='"+nameString+"EventIndicator' id='"+nameString+"EventIndicator"+idcounter+"' value='"+tableId+idcounter+"'>";
      tdString += "<input type=hidden name='"+nameString+"EventNo' id='"+nameString+"EventNo"+idcounter+"' value=''>";
      tdString += "<input type=hidden name='"+nameString+"ShipmentEventNo' id='"+nameString+"ShipmentEventNo"+idcounter+"' value=''>";
      tdString += "<input type=hidden name='"+nameString+"EventCustomer' id='"+nameString+"EventCustomer"+idcounter+"' value=''>";

      tdString += "<input type=hidden name='"+nameString+"EventIsSuggested' id='"+nameString+"EventIsSuggested"+idcounter+"' value='N'>";
      parentTableRow.appendChild(createTDWithHTML(tdString));
      
      if(!generalEventsFlag)
            parentTableRow.appendChild(createTDWithHTML("<select parentTableId='"+tableId+"' onChange=\"setEventCustomer(this,'referenceEventCustomer',"+idcounter+");\" onKeyDown='trapDynamicContentRowKeyDown(event);' name='"+nameString+"EventPartyType' id='"+nameString+"EventPartyType"+idcounter+"' class=select><option value='R'>Customer</option><option value='S'>Shipper</option><option value='C'>Consignee</option></select>"));
      
      var showEventsString = "";

      if(generalEventsFlag)
            showEventsString = "showEvents(\"generalReferenceEvent\","+idcounter+")";
      else
            showEventsString = "showEvents(\"partyReferenceEvent\","+idcounter+")";

      parentTableRow.appendChild(createTDWithHTML("<input parentTableId='"+tableId+"' onKeyDown='trapDynamicContentRowKeyDown(event);' class=text name='"+nameString+"EventCode' id='"+nameString+"EventCode"+idcounter+"' size=5>&nbsp;<input name='"+nameString+"EventCodeLOV' id='"+nameString+"EventCodeLOV"+idcounter+"' type=button class=input value='...' onClick='"+showEventsString+"'>"));
      parentTableRow.appendChild(createTDWithHTML("<input parentTableId='"+tableId+"' onKeyDown='trapDynamicContentRowKeyDown(event);' class=text name='"+nameString+"EventDescription' maxlength=20 id='"+nameString+"EventDescription"+idcounter+"' size=25>"));
      parentTableRow.appendChild(createTDWithHTML("<input parentTableId='"+tableId+"' onKeyDown='trapDynamicContentRowKeyDown(event);' class=text size=15 maxlength=25 name='"+nameString+"EventRefId' id='"+nameString+"EventRefId"+idcounter+"'>&nbsp;<input name='"+tableId+"addButton' type=button value='>>' class=input onClick='createRow(\""+tableId+"\","+generalEventsFlag+");'>"));

      parentTableCell                              = document.createElement("TD");
      parentTableCell.setAttribute("id",tableId+"DynamicTD");
      parentTableCell.setAttribute("colspan","2");
      parentTableCell.appendChild(createSubRow(tableId));
      parentTableRow.appendChild(parentTableCell);      

      parentTableBody.appendChild(parentTableRow);
      parentTable.appendChild(parentTableBody);
      idcounter++;
      parentTable.setAttribute("idcounter",idcounter);
      handleAddButtons(tableId+"addButton");

//added by sampath
      if(tableId=='generalPartyReferencesEventsTable')
      {
            check(tableId);
      }
//end

}

// added by sampath
function check(tableId)
{
      var parentTable                  = document.getElementById(tableId);
      var idcounter                  = parentTable.getAttribute("idcounter");

//                  document.getElementById('Next').style.visibility='hidden';
//                  document.getElementById('Prev').style.visibility='hidden';

            var totalRows=0;
            for (var lc=0; lc<idcounter; lc++)
            {
            
                  if (document.getElementById('generalReferenceEventCode'+lc)!=null)
                  {
                        totalRows=(totalRows*1)+1;
                  }
            }
            if (totalRows==50)
            {
                  alert("created 50 rows");
                  document.getElementById('Next').style.visibility='visible';
                  document.getElementById(tableId+'addButton').style.visibility='hidden';

            }


}
//end
function createTDWithHTML(tdInnerHTML)
{
      if(tdInnerHTML==null)
            tdInnerHTML = "";
      myTableCell                              = document.createElement("TD");
      myTableCell.innerHTML      = tdInnerHTML;
      myTableCell.align      = "center";
      return myTableCell;
}

</SCRIPT>



<!-- added by sampath uppula on 9/16/2004 -->

                  <table border='0' width="<%=tableWidth%>" cellspacing='1' cellpadding='2' nowrap>
                   <tr>
                        <td>
                              <input type='button' id='Prev' class=input value='<-' onClick='showPrevPage();' style='visibility:hidden'>
                        </td>
                        <td>
                              <input type='button' id='Next' class=input value='->' onClick='showNextPage();' visibility='false' style='visibility:hidden'>
                        </td>
                  </tr>
                  </table>
<!-- End -->            



LVL 20
chaitu chaituAsked:
Who is Participating?
 
MogalManicConnect With a Mentor Commented:
Your javascript is so large and complex that it is impossible to separate Javascript from JSP.  My first suggestion is to modularize your javascript code and build an API that is easy to add/insert rows to your page.  Maybe something like this:
<html>
   <head>
      <script type='text/html' src='DynamicRows.js'></scripts><!-- This is the guts of the javascript -->
      <script type='text/html'>
               BuildRow(<%/*Build your row data*/%>
               //OR
               <%
                       for(int i=0;i<dataLength;i++) {
                           out.println("BuildRow("+...+");");
                            ...
                       }
                %>
      </script>
...Rest of page...
      <script type='text/html'>
             StartDynamicContent()
      </script>
0
 
CodingExpertsConnect With a Mentor Commented:
You may use this link to find a DBGrid for JSP with complete implementation

http://www.codeproject.com/useritems/DBGrid.asp

Good Luck
CodingExpert
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.