Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation paging for dynamic rows

    hi

    I AM IMPLEMENTING PAGING(NEXT AND PREVIOUS BUTTONS) FOR DYNAMIC ROWS
    PER PAGE I AM DISPLAYING 3 RECORDS;

    NO_of_pieces Method_Of_Pkg Actual_Wt
    << textbox(0,0) textbox(0,1) textbox(0,2) >>
    << textbox(1,0) textbox (1,1) textbox(1,2)
    << textbox(2,0) textbox (2,1) textbox(2,2)

    Next Previous

    I AM DOING THIS APPLICATION USING 2 DIMENSIONAL ARRAY;

    I AM SETTING DATA IN SESSION WITH PAGE NUMBER IN SERVLET

    I AM DISPLAYING SESSION DATA IN JSP LIKE THIS

    String formData[][] = (String[][])session.getAttribute("myFormDataForPage"+pageNo);

    MY PROBLEM IS I AM ENTERING DATA IN 3 ROWS after that CLICKING NEXT BUTTON AND GOING TO 2ND PAGE THEN IN THE 2ND PAGE I AM CLICKING PREVIOUS BUTTON TO SEE THE FIRST PAGE DATA ;I AM ABLE TO SEE THE 1ST PAGE DATA BUT I WANT TO DISPLAY DATA IN MY JSP PAGE I AM WRITING CONDITION LIKE THIS

    If(formData != null)
    IAM CALLING addRow('myTable') FUNCTION

    I AM GETTING EXCEPTION PAGE NOT FOUND

    why i am calling like this because

    as u can see the addRow(id) function

    for every dynamic row i am putting the remove button at the left side(user can have choice of deleting the row)

    i want to call this Javascript function addRow() for satisfying IN both Add and Modify operations and also it will satisfy in Next and Previous modes;

    i hope i explained problem well;



    <%@ page import="example.DynamicRow,java.util.*" %>
    <%
    String Pageno =(String)(request.getAttribute("PageNo") != null ? request.getAttribute("PageNo") : "1");
    int pageNo =0;
    if(Pageno != null)
    {
    pageNo=Integer.parseInt(Pageno);
    }

    String formData[][] = (String[][])session.getAttribute("myFormDataForPage"+pageNo);

    if(formData != null)
    {
    System.out.println("formData in jsp ="+formData.length);
    }


    %>

    <html>
    <head>
    <title>Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/JavaScript">
    j=0;
    i=1;
    function addRow(id){
    var no_of_pieces = "<input type='text' name='mytextbox"+i+j+"_<%=pageNo%>' size='4' >";
    j++;
    var Method_Of_Pkg = "<input type='text' name='mytextbox"+i+j+"_<%=pageNo%>' size='10' >";
    j++;
    var Actual_Wt = "<input type='text' name='mytextbox"+i+j+"_<%=pageNo%>' size='8' >";
    j=0;
    var remove = "<input type='button' value='<<' onClick='remove(this.parentNode.parentNode.rowIndex)'>";


    var tbody = document.getElementById(id).getElementsByTagName("TBODY" )[0];

    var row = document.createElement("TR" )

    var td0 = document.createElement("TD" )
    td0.appendChild(document.createElement(remove))

    var td1 = document.createElement("TD" )
    td1.appendChild(document.createTextNode(i))


    var td2 = document.createElement("TD" )
    td2.appendChild (document.createElement(no_of_pieces))

    var td3 = document.createElement("TD" )

    td3.appendChild (document.createElement(Method_Of_Pkg))

    var td4 = document.createElement("TD" )
    td4.appendChild (document.createElement(Actual_Wt))


    i=i+1;
    row.appendChild(td0);
    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);


    Rows = document.getElementById('myTable').rows
    lastRow = Rows[Rows.length-1]
    addButton = lastRow.lastChild
    row.appendChild(lastRow.removeChild(addButton));
    tbody.appendChild(row);

    if(Rows.length-2 == 3)
    {
    document.getElementById("addtag").style.display ="none";
    document.getElementById("Next").style.display ="";
    }

    }

    function remove(rowIndex){
    var table = document.getElementById('myTable');
    var rows = table.rows;

    if(rowIndex == rows.length-1) rows[rows.length-2].appendChild(rows[rows.length-1].removeChild(addButton))
    table.deleteRow(rowIndex);
    i--;
    if(rows.length > rowIndex)
    for (k = rowIndex; k < rows.length; k ++)
    rows[k].cells[1].innerHTML = k;

    }


    function ex(){
    var rows=document.getElementsByTagName("TR");

    for (j = 1; j < rows.length; j ++) {
    inputs = rows[j].getElementsByTagName("input");
    alert(inputs[j].value)
    }

    }

    function ex1(){
    alert("aa")
    }

    </script>
    </head>

    <body>
    <form action="DynamicController?PageNo=<%=pageNo%>">
    <table id="myTable" cellspacing="0" border="2">
    <tr>
    <td> </td>
    <td><b>Sno</td>
    <td><b>No of Pieces</td>
    <td><b>Method Of Pkg</td>
    <td><b>Actual Wt</td>
    <td> </td>
    </tr>
    <tr>
    <%
    if(formData == null || "".equals(formData))
    {%>

    <td> </td>
    <td>1</td>
    <td>
    <input type=text name="mytextbox00_<%=pageNo%>" value ="" >
    </td>
    <td>
    <input type=text name="mytextbox01_<%=pageNo%>" value ="" >
    </td>
    <td>
    <input type=text name="mytextbox02_<%=pageNo%>" value ="" >
    </td>
    <td><input type='button' name='add1' value='>>' id="addtag" onClick="addRow('myTable');" style="display:''"></td>
    <%}%>
    </tr>

    <%

    if(formData != null)
    {
    for(int i=0;i<3;i++)
    {%>
    <tr> <td> </td> <td><%=i+2%></td>
    <% for(int j=0;j<3;j++)
    {%>
    <script>
    addRow(document.getElementsByTagName('myTable'));
    </script>
    <!-- <td> <input type="text" name='mytextbox<%=i%><%=j%>_<%=pageNo%>' value ='<%=formData[j]%>'></td> -->

    <%}%>
    </tr>

    <%}}%>
    <tr>
    <td colspan="11"><input type='submit' name='save' value='Save' onClick="ex()";>
    <input type='submit' name='Next' id="Next" value='Next' style="display:none">
    <input type='submit' name='Previous' id="Previous" value='Previous' style="display:none">
    </td>
    </tr>
    <input type=hidden name="rows" value = "3">
    <input type=hidden name="cols" value = "3">
    <input type=hidden name="pageNumber" value="<%=pageNo%>">
    </tr>
    </table>
    <script>

    var pageno ="<%=pageNo%>"

    if("<%=pageNo%>" >= 1)
    {
    document.getElementById("Next").style.display ="";
    document.getElementById("Previous").style.display ="";
    }
    </script>

    </form>
    </body>
    </html>

    Comment from chaituu
    Date: 09/28/2004 06:37AM PDT
    Author Comment


    MY SERVLET


    package example;
    import example.DynamicRow;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.PrintWriter;
    import java.io.IOException;
    import java.util.*;


    public class DynamicController extends HttpServlet
    {
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

    ArrayList requestList = null;
    Hashtable ht = null;
    public void init(ServletConfig config) throws ServletException
    {
    super.init(config);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {

    HttpSession session = request.getSession();
    String[] no_of_pieces = request.getParameterValues("no_of_pieces");
    String[] method_of_pack = request.getParameterValues("method_of_pack");
    String[] actual_wt = request.getParameterValues("actual_wt");

    String pageNumber = request.getParameter("pageNumber");
    String rows= request.getParameter("rows");
    String cols= request.getParameter("cols");

    int rowItr = Integer.parseInt(rows);
    int colItr = Integer.parseInt(cols);
    String formData[][] = new String[3][3];

    for(int i=0;i<3;i++)
    {
    for(int j=0;j<3;j++)
    {
    System.out.println("mytextbox"+i+j+"_"+pageNumber+"....request......."+request.getParameter("mytextb ox"+i+j+"_"+pageNumber));
    formData[i][j] = request.getParameter("mytextbox"+i+j+"_"+pageNumber);

    }
    }

    session.setAttribute("myFormDataForPage"+pageNumber, formData);


    int pageNo =0;
    String task =null;

    if(pageNumber != null)
    {
    pageNo=Integer.parseInt(pageNumber);
    }


    if(request.getParameter("Next") != null)
    {
    task =request.getParameter("Next");
    pageNo++;

    }
    else if(request.getParameter("Previous") != null)
    {
    task = request.getParameter("Previous");
    pageNo--;
    }


    request.setAttribute("PageNo",pageNo+"");
    request.setAttribute("task",task);
    doDispatcher(request,response,"/AddingRows.jsp");

    }



    I THINK I AM GETTING PROBLEM WITH JAVASCRIPT HOW TO DISPLAY DATA CALLING THE JAVASCRIPT FUNCTION addRow();

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if it's just a JS problem, then you don't need to post all your Java. just need the relevant part. also, use the supplied code tags when posting. it makes it easier to read.

    thanks
    *keep it simple (TM)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •