Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JSP Paging: URGENT

Posted on 2006-04-21
15
Medium Priority
?
386 Views
Last Modified: 2008-01-09
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
Comment
Question by:suketu9
  • 5
  • 4
  • 3
12 Comments
 
LVL 19

Expert Comment

by:actonwang
ID: 16509211
>>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
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 2000 total points
ID: 16509215
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
 
LVL 19

Expert Comment

by:actonwang
ID: 16509269
>>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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:suketu9
ID: 16509272
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
 

Author Comment

by:suketu9
ID: 16509385
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
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16509423
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
 
LVL 19

Expert Comment

by:actonwang
ID: 16509439
shivaspk,

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

Acton
0
 
LVL 19

Expert Comment

by:actonwang
ID: 16509464
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
 

Author Comment

by:suketu9
ID: 16509632
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
 
LVL 19

Expert Comment

by:actonwang
ID: 16509687
oh, man,

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

Acton
0
 

Author Comment

by:suketu9
ID: 16509764
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
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16513651
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Will the future of mobile app development include the same trends as those most relevant today? Find out by checking out the 7 trends of the future.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

810 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