Solved

implement paging to dynamic rows

Posted on 2004-09-17
4
219 Views
Last Modified: 2010-04-01
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 -->            



0
Comment
Question by:chaitu chaitu
4 Comments
 
LVL 21

Accepted Solution

by:
MogalManic earned 250 total points
ID: 12091350
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
 
LVL 6

Assisted Solution

by:CodingExperts
CodingExperts earned 250 total points
ID: 12095173
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 104
Lamba in java 8 9 239
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 542
oracle fusion vs MQ 2 107
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now