• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

JSP Paging: URGENT

I have implement pagertag library for jsp paging in my jsp page. In my jsp page it now displays 10 records per page and also I can select all of those records or select one record and click save at the bottom of the page to save that record in database. But now we want to select one or all records and instead of saving at each page we want to select as many records we want on each page and save it at the last page. How can these be done. I am not sure. I am posting my jsp page code here. Please help out its URGENT.

<%@ page import="com.ko.saprofile.util.*" %>
<%@ page import="com.ko.saprofile.bo.*" %>
<%@ page import="com.ko.saprofile.fdo.*" %>
<%@ page import="java.util.*" %>
<%@ include file="/includes/errors.jsp" %>
<%@ include file="/includes/insertBackslash.jsp" %>
<%@ include file="/includes/getDisplayable.jsp" %>
<%@ include file="/includes/LogRequestDiagnosis.jsp" %>
<!-- Added following tag for using pager-taglib.tld for paging -->
<%@ taglib uri="/WEB-INF/pager-taglib.tld" prefix="pg" %>

<%  logRequestDiagnosis(request);
     String errorMsg = (String)session.getAttribute(Constants.ERROR_MESSAGE);
     System.out.println("Error Msg is " + errorMsg);
     if (errorMsg == null) {
          errorMsg = new String();
     }
     String docRoot = Props.getProperty(Props.WEBAPP_WEBPATH);
//    String state = (String)session.getAttribute(Constants.APPL_STATE);//commented this for paging in jsp.
    System.out.println("I AM IN OMTOPROVIDER");
   
 //Following two statement were added for paging in jsp. 03/28/06. Also I had to change req to session for
 //userBO, agentBO, transtoken, collection.  
    String state = (String)request.getParameter(Constants.APPL_STATE);
      String value= States.REALIGN_OM_TO_PROVIDER;
///////////////////////////////////////////////////////////////////////////

    System.out.println("state is " + state);
     if (state == null || !state.equals(States.REALIGN_OM_TO_PROVIDER)) {
          // Unauthorized source, redirect to parent Controller and let it handle it
          out.println("Access violation!");
        return;
     }
     String transToken = (String)session.getAttribute(TransToken.OBJNAME);
     System.out.println("TransToken is " + transToken);
     if (transToken == null) {
          System.out.println("TransToken is null");
       
    }
     UserBO userBO = (UserBO)session.getAttribute(UserBO.OBJNAME);
     System.out.println("UserBO is " + userBO);
     if (userBO == null) {
          System.out.println("USERBO is null");
       
    }
     AgentBO agentBO = (AgentBO)session.getAttribute(AgentBO.OBJNAME);
     System.out.println("AGENTBO is " + agentBO);
     if (agentBO == null) {
          System.out.println("TransToken is null");
       
    }
    Collection collection = (Collection)session.getAttribute(OmToProviderBO.OBJNAME);
    if (collection == null) {
          out.println("Collection is null");
        collection = new Vector();
    }
    System.out.println("Collection size is " + collection.size());
   
    Iterator itor = collection.iterator();
    Iterator itorJS1 = collection.iterator();
    Iterator itorJS2 = collection.iterator();
    OmToProviderFDO fdo = (OmToProviderFDO)session.getAttribute(OmToProviderFDO.OBJNAME);
    System.out.println("fdo is " + fdo);
    if (fdo == null) {
          out.println("fdo is null");
       
    }
%>
<HTML>
<HEAD>
<!-- Making use of page tag library. This is for paging. 03/28/06 -->
<pg:pager maxIndexPages="25" maxPageItems="10"
      export="currentPageNumber=pageNumber"
      scope="request">
      <pg:param name="ApplicationState" value="RealignOmToProviderState"></pg:param>
     <LINK rel="stylesheet" type="text/css" href="CSS/realign.css">
     <META http-equiv="Expires" content="0">
     <TITLE>OM to Provider Realignment</TITLE>  
     <SCRIPT language="javascript" src="/spps/javascript/dataValidation.js"></SCRIPT>
     <SCRIPT language="javascript" src="/spps/javascript/errors.js"></SCRIPT>
     <SCRIPT language="javascript" src="/spps/javascript/header.js"></SCRIPT>
     <SCRIPT language="javascript" src="/spps/javascript/realign.js"></SCRIPT>    
          <SCRIPT language="javascript">
    function saveUpdates(){
        //loadSelectedAgents();
        //if (validForm()) {
            document.<%= Forms.OM_TO_PROVIDER %>.<%=Constants.USER_ACTION%>.value = "<%=Constants.SAVE%>";
            document.<%= Forms.OM_TO_PROVIDER %>.submit();
           
       // }
    }

    function cancelbatch(){
        document.<%= Forms.OM_TO_PROVIDER %>.<%=Constants.USER_ACTION%>.value = "<%=Constants.CANCEL%>";
            <% System.out.println("I am in validForm");%>
        document.<%= Forms.OM_TO_PROVIDER %>.submit();
    }
   
    /* ****begin COMMENTED BY SCSL OFFSHORE FOR RFS #5102  ON DATE 24-Aug-2005 ***** */
    function checkUncheckAll(){
         //alert("checkUncheckAll");
               
         if( document.<%= Forms.OM_TO_PROVIDER %>.toggleAll.checked ){
              //alert("all check boxes were selected");
               for( i=6; i <= document.<%= Forms.OM_TO_PROVIDER %>.elements.length-3 ; i++ ){
                    if( document.<%= Forms.OM_TO_PROVIDER %>.elements[i] != null ){
                         document.<%= Forms.OM_TO_PROVIDER %>.elements[i].checked = true;
                    }
               }                
         }else{
              //alert("all check boxes were unslected");
               for( i=6; i <= document.<%= Forms.OM_TO_PROVIDER %>.elements.length-3 ; i++ ){
                    if( document.<%= Forms.OM_TO_PROVIDER %>.elements[i] != null )
                         document.<%= Forms.OM_TO_PROVIDER %>.elements[i].checked = false;
               }
         }
    }
    /* ****end COMMENTED BY SCSL OFFSHORE RFS FOR #5102  ON DATE 24-Aug-2005 ***** */

     </SCRIPT>

</HEAD>
<BODY LANGUAGE=javascript onload="serverError('<%= errorMsg %>');">
<TABLE WIDTH=100% STYLE="background-color=white;" BORDER=0 CELLPADDING=2 CELLSPACING=2>
     <TR><TD><%@ include file="/includes/header.jsp" %></TD></TR>
     <% System.out.println("I am after header.jsp"); %>
    <TR><TD><CENTER>
   
     




<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 STYLE="width=700px;background-color=white;" ID="DataTable">
    <FORM NAME="<%= Forms.OM_TO_PROVIDER %>" Method="post" Action="<%= docRoot %>/OmToProvider">
     <INPUT TYPE="HIDDEN" NAME="<%= Constants.USER_ACTION %>"  VALUE="noValue">
     <INPUT TYPE="HIDDEN" NAME="<%= TransToken.OBJNAME %>"  VALUE="<%= transToken %>">
     <INPUT TYPE="HIDDEN" NAME="<%= OmToProviderFDO.FROM_SRVID %>"  VALUE="<%= fdo.getFromSrvid() %>">
     <INPUT TYPE="HIDDEN" NAME="<%= OmToProviderFDO.TO_SRVID %>"  VALUE="<%= fdo.getToSrvid() %>">
     <INPUT TYPE="HIDDEN" NAME="<%= Forms.NAME %>"  VALUE="<%= Forms.OM_TO_PROVIDER %>">
     
    <tr CLASS="MAJORHEADING" height=20>
        <td colspan=7 ALIGN="CENTER">OM to Provider Alignment (Provider Selection)</td>
    </tr>
    <tr height=20><td colspan=7 ALIGN="CENTER">&nbsp;</td></tr>
    <TR><TD COLSPAN=7 ALIGN="CENTER">
        <TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 STYLE="background-color=white;">
            <TR><TD WIDTH=40% ALIGN="RIGHT"><B>From OM:</B></TD><TD WIDTH=60% ALIGN="LEFT"><%= fdo.getFromSrvidName() %></TD></TR>
            <TR><TD WIDTH=40% ALIGN="RIGHT"><B>To OM:</B></TD><TD WIDTH=60% ALIGN="LEFT"><%= fdo.getToSrvidName() %></TD></TR>
        </TABLE></TD>
    </TR>
    <tr height=20><td colspan=7 ALIGN="CENTER">&nbsp;</td></tr>
    <TR><TD ALIGN="CENTER" CLASS="smallboldtext" STYLE="border-style:solid;border-width:1px;border-color:black;">Group</TD>
        <TD ALIGN="CENTER" CLASS="smallboldtext" STYLE="border-style:solid;border-width:1px;border-color:black;">ACN</TD>
        <TD ALIGN="CENTER" CLASS="smallboldtext" STYLE="border-style:solid;border-width:1px;border-color:black;">Name</TD>
        <TD ALIGN="CENTER" CLASS="smallboldtext" STYLE="border-style:solid;border-width:1px;border-color:black;">City, St</TD>
        <TD ALIGN="CENTER" CLASS="smallboldtext" STYLE="border-style:solid;border-width:1px;border-color:black;">Code</TD>
        <TD ALIGN="CENTER" CLASS="smallboldtext" STYLE="border-style:solid;border-width:1px;border-color:black;">Whlslr</TD>
        <TD ALIGN="RIGHT" CLASS="smallboldtext" STYLE="border-style:solid;border-width:1px;border-color:black;" nowrap="nowrap">
        <!--/* ****begin COMMENTED BY SCSL OFFSHORE FOR RFS #5102  ON DATE 24-Aug-2005 ***** */-->
        Select All<INPUT type="checkbox" name="toggleAll" onclick="checkUncheckAll()" CHECKED>
        <!--/* ****end COMMENTED BY SCSL OFFSHORE FOR RFS #5102  ON DATE 24-Aug-2005 ***** */--></TD>
    </TR>
<%  
     
     while (itor.hasNext()) {
        OmToProviderBO bo = (OmToProviderBO)itor.next();
%>  

<pg:item><!-- Pag tag for paging -->
<TR><TD ALIGN="CENTER" CLASS="smalltext" STYLE="border-style:solid;border-width:1px;border-color:black;">
            <%= bo.getSrvidArea() %></TD>
        <TD ALIGN="CENTER" CLASS="smalltext" STYLE="border-style:solid;border-width:1px;border-color:black;">
            <%= String.valueOf(bo.getAgentACN()) %></TD>
        <TD ALIGN="LEFT" CLASS="smalltext" STYLE="border-style:solid;border-width:1px;border-color:black;">
            <%= bo.getAgentName() %></TD>
        <TD ALIGN="LEFT" CLASS="smalltext" STYLE="border-style:solid;border-width:1px;border-color:black;">
            <%= getDisplayableNBSP(bo.getAgentCityState()) %></TD>
        <TD ALIGN="CENTER" CLASS="smalltext" STYLE="border-style:solid;border-width:1px;border-color:black;">
            <%= bo.getAgentCode() %></TD>
        <TD ALIGN="CENTER" CLASS="smalltext" STYLE="border-style:solid;border-width:1px;border-color:black;"
            Title="<%= bo.getWholeSellerTypeDesc() %>">
            <%= getDisplayableNBSP(bo.getWholeSellerType()) %></TD>
        <TD ALIGN="RIGHT" CLASS="smalltext" STYLE="border-style:solid;border-width:1px;border-color:black;">
             <INPUT TYPE="CHECKBOX" NAME="<%= OmToProviderFDO.SELECTED_AGENTS %>" VALUE="<%= bo.getAgentACNCode() %>" CHECKED ></TD>
    </TR>
   

</pg:item>


<%     }  %>
 
<%  if (!collection.isEmpty()) { %>
    <tr height=20><td colspan=7 ALIGN="CENTER">&nbsp;</td></tr>
    <TR><TD ALIGN="CENTER" COLSPAN=7>
            <INPUT CLASS="DfltButton" TYPE="BUTTON" value="Cancel" onclick="javascript:cancelbatch();">
            &nbsp;&nbsp;<INPUT CLASS="DfltButton" TYPE="BUTTON" value="Save" onclick="javascript:saveUpdates();">
        </TD>
    </TR>
<%  } else { %>
    <tr height=20><td colspan=7 ALIGN="CENTER">No Providers found</td></tr>
    <tr height=20><td colspan=7 ALIGN="CENTER">&nbsp;</td></tr>
    <TR><TD ALIGN="CENTER" COLSPAN=7>
            <INPUT CLASS="DfltButton" TYPE="BUTTON" value="Cancel" onclick="javascript:cancelbatch();">
        </TD>
    </TR>
<%  } %>
    </FORM>
</TABLE></CENTER>

     </TD></TR>
</TABLE>    
<%
    if (agentBO == null) {
    System.out.println("I am in agentBO = null if loop of javascript");
%>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="/spps/javascript/HM_LoaderNoAgent.js" TYPE='text/javascript'></SCRIPT>
<%
    } else {
    System.out.println("I am in agentBO = NOT null if lool of javascript");
%>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="/spps/javascript/HM_Loader.js" TYPE='text/javascript'></SCRIPT>
<%
    }
%>

<%--this is for page indexing ** starts here**. For paging in jsp . 03/28/06--%>

<pg:index>
    <font face=Helvetica size=-1 color=ActiveCaption>Result Pages:
    <pg:prev>&nbsp;<a href="<%= pageUrl %>" style="text-decoration:none">[&lt;&lt; Prev]</a></pg:prev>
    <pg:pages><%
      if (pageNumber.intValue() < 10) {
        %>&nbsp;<%
      }
      if (pageNumber == currentPageNumber) {
        %><b><%= pageNumber %></b><%
      } else {
        %><a href="<%= pageUrl %>" style="text-decoration:none"><%= pageNumber %></a><%
      }
    %>
    </pg:pages>
    <pg:next>&nbsp;<a href="<%= pageUrl %>" style="text-decoration:none">[Next &gt;&gt;]</a></pg:next>
    <br></font>
  </pg:index>
 
</pg:pager>
</BODY>
</HTML>
0
suketu9
Asked:
suketu9
  • 5
  • 4
  • 3
1 Solution
 
actonwangCommented:
>>save it at the last page
     when you click save button, you can invoke a servlet which will retrieve all records if it is in the last page.
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
ok try this when ever user clicks save go on putting those records in hashMap and keep this hash Map in session and at the end after displaying all the records get back the records from the session and save them i think this is one of the way to do it in a simple way.

Thank You.
0
 
actonwangCommented:
>>putting those records in hashMap and keep this hash Map in session
     what if there are a lot of records? Also what if user never hits save button. Would it be a waste then?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
suketu9Author Commented:
I am new to Java, so if any of you can give some code ,based on my code posted above, that would be great. This is URGENT please help.

Thanks
0
 
suketu9Author Commented:
I dont think hashmap would be right since we will have more than 30000 records and user can decide to select all and save. So what is the best way to do this and if someone can show me the code based on my above jsp post.  Also since number pages will vary based on number of records where will save button go and how will it save all the selected reocrds. I am new to Java so dont know where or how to start. Please help.

Thanks
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
actonwang  I think you need to read the question correctly and About

>> Also what if user never hits save button. Would it be a waste then?

Having an Empty Hash MAp in Session may not cause any major issue.

 actonwang if you can help him as i need to move.

Bye.
 
0
 
actonwangCommented:
shivaspk,

        I think you need to read the question carefully. hashmap in the session? no. not a option here.

Acton
0
 
actonwangCommented:
suketu9,

         when user clicks the save button, in which format the user wants to see or download all 30000 records?

         as I said, it would be simple jsp or servlet to serve this request. I don't see any difficulty here.

Acton
0
 
suketu9Author Commented:
Let me be more clear. I display 10 records per page and in each page their is a save button. So I can select all 10 records or one record by clicking the check box next to the record and then click save button , then it will save the record to the database. Currently we can select record and save that record to database on same page, but we want to select whatever records we want in each page then when we hit SAVE it should save all the records that are selected on each page. For example:

In page 1: I select 2 records, then click page 2.
In page 2: I select 4 records, then click page 3.
In page 3: I select 1 record, then click save and it should save all the records in database that were selected in page1, page2 and page3.

Please let me know what changes I need to make in my jsp posted above in the post.

Thanks
0
 
actonwangCommented:
oh, man,

    shivaspk is right. You need to save those records into session as a collection.

Acton
0
 
suketu9Author Commented:
I do have records in collection from collection it displays 10 records per page, but what should I do when I check one of the records, click on page 2 check 2 records, click page 3 check 1 records and hit save it should save all of those records in a database. What do I need to do so that each checked record is saved in database when I click save on page 3.

Thanks
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
suketu9 when the user check that record get that record from the current collection which you are using to display and put it in a Has Map which is in the session, this is a diffrent collection (HashMap) which contains only the records which were selected or checked by the User and then finally at the Lat page you will be having a HashMap which contains only the checked record in diffrent pages now when the user click save button get the records from this collection and save them to the database.

One more thing you need to take care is if the user goes back and unchecks a checked record you need to delete this fromm the HashMap which you will be using to get only the checked records. So that only checked records will e there finally.
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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now