jsf pagination

jsf pagination

Hi ,

i want to paginate some questions in jsf for online exam . i want to select 1st question by click on 1st link and so on

please give any solution .

Thanks, Bhuban

View Answers

July 30, 2012 at 11:17 AM

Here is a jsp code of pagination. In the given code,we have taken the database table student(rollNo,name,marks,grade).

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%!
public int nullIntconvert(String str){
int num=0;
if(str==null) {
str="0";
}
else if((str.trim()).equals("null")) {
str="0";
}
else if(str.equals("")) {
str="0";
}
try{
num=Integer.parseInt(str);
}
catch(Exception e) { }
return num;
}
%>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
ResultSet rs1 = null;
ResultSet rs2 = null;
PreparedStatement ps1=null;
PreparedStatement ps2=null;

int showRows=10;
int totalRecords=10;
int totalRows=nullIntconvert(request.getParameter("totalRows"));
int totalPages=nullIntconvert(request.getParameter("totalPages"));
int iPageNo=nullIntconvert(request.getParameter("iPageNo"));
int cPageNo=nullIntconvert(request.getParameter("cPageNo"));

int startResult=0;
int endResult=0;
if(iPageNo==0) {
iPageNo=0;
}
else{
iPageNo=Math.abs((iPageNo-1)*showRows);
}
String query1="SELECT SQL_CALC_FOUND_ROWS * FROM student limit "+iPageNo+","+showRows+"";
ps1=conn.prepareStatement(query1);
rs1=ps1.executeQuery();

String query2="SELECT FOUND_ROWS() as cnt";
ps2=conn.prepareStatement(query2);
rs2=ps2.executeQuery();
if(rs2.next()) {
totalRows=rs2.getInt("cnt");
}
%>
<html>
<h3>Pagination of JSP page</h3>
<body>
<form>
<input type="hidden" name="iPageNo" value="<%=iPageNo%>">
<input type="hidden" name="cPageNo" value="<%=cPageNo%>">
<input type="hidden" name="showRows" value="<%=showRows%>">
<table width="100%" cellpadding="0" cellspacing="0" border="1" >
<tr>
<td>Roll No</td>
<td>Name</td>
<td>Marks</td>
<td>Grade</td>
</tr>
<%
while(rs1.next()) {
%>
<tr>
<td><%=rs1.getInt("rollNo")%></td>
<td><%=rs1.getString("name")%></td>
<td><%=rs1.getInt("marks")%></td>
<td><%=rs1.getString("grade")%></td>
</tr>
<%
}
%>

July 30, 2012 at 11:18 AM

continue..

<%
try{
if(totalRows<(iPageNo+showRows)) {
endResult=totalRows;
}
else{
endResult=(iPageNo+showRows);
}
startResult=(iPageNo+1);
totalPages=((int)(Math.ceil((double)totalRows/showRows)));
}
catch(Exception e){
e.printStackTrace();
}
%>
<tr>
<td colspan="3">
<div>
<%
int i=0;
int cPage=0;
if(totalRows!=0) {
cPage=((int)(Math.ceil((double)endResult/(totalRecords*showRows))));

int prePageNo=(cPage*totalRecords)-((totalRecords-1)+totalRecords);
if((cPage*totalRecords)-(totalRecords)>0){
%>
<a href="pagination.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
<%
}
for(i=((cPage*totalRecords)-(totalRecords-1));i<=(cPage*totalRecords);i++){
if(i==((iPageNo/showRows)+1)){%>
<a href="pagination.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
<%
}
else if(i<=totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>"><%=i%></a>
<%
}
}
if(totalPages>totalRecords && i<totalPages){
%>
<a href="pagination.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a>
<%
}
}
%>
<b>Rows <%=startResult%> - <%=endResult%> Total Rows <%=totalRows%> </b>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<%
try{
if(ps1!=null){
ps1.close();
}
if(rs1!=null){
rs1.close();
}

if(ps2!=null){
ps2.close();
}
if(rs2!=null){
rs2.close();
}

if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>

Save the code with the name pagination.jsp.

Hope that it will be helpful for you.









Related Tutorials/Questions & Answers:
jsf pagination
jsf pagination  Hi , i want to paginate some questions in jsf... of pagination. In the given code,we have taken the database table student(rollNo,name,marks...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
pagination in jsf
pagination in jsf  Hi , i am implemeting an online exam system , i have placed my questions as an arraylist in my jsp file within tag , but now i want to paginate these questions based on respective questions by clicking
Advertisements
Pagination
Pagination  How to create pagination in jsp with EJB using MS SQL
Pagination
Pagination  How to implement pagination in struts using hibernate
Pagination
Pagination  How to apply pagination in JSP. Please help
pagination
pagination  How to set pagination using java script to display data
pagination
pagination   Simple way for pagination in jsp using java script to display data without send database
Pagination
Pagination  Is their plug n play approach for creating pagination? 1) Server side as well as client side
Pagination
Pagination  I want to write one where condition in sql query in pagination concept
Pagination
Pagination  I want to know how to use pagination in jsp. I have a list object from that i want to display 3 questions per page can u help me
pagination
pagination  i want to make online exam server by jsf 1.2 please tell... code of pagination. In the given code,we have taken the database table student...;Pagination of JSP page</h3> <body> <form> <input type="hidden
pagination
pagination  I need to give pagination with where condition (query="select * from qtn where qid='"+replyQuesionId+"'limit "+iPageNo+","+showRows+"" ) like this I want, without where condition it is working but with condition
pagination
pagination  I need to give pagination with where condition (query.......   Here is a simple jsp pagination code where we have used mysql database...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
Pagination
=rs2.getInt("cnt"); } %> Pagination of JSP page Terr_Code Terr_Name
pagination
pagination  how can i start pagination in jsp?   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import...;Pagination of JSP page</h3> <body> <form> <input type="hidden
Pagination
Pagination  pagination in jsp   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import="java.sql.*" %>...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
JSF
JSF  What is JSF
JSF
JSF  In what way JSF makes the difference between Applets?? After reading this article I understood instead of using Request and response, we... and embed that into applets also rite.. Do u mean JSF also does the same internally
Pagination in java
Pagination in java  How to handle pagination when there are records like say in millions in java? Or do we handle this using SQL? I as asked... far good performance then Java pagination. Thanks
jsp pagination
jsp pagination  I want to implement pagination on jsp page Each jsp page having some radio buttons, on click of next previous page selected radio buttons are reset. I want to maintain state of selected radio buttons on previous
Hibernate Pagination
In this tutorial we will discuss concept of pagination in hibernate
pagination
Pagination
Pagination
Pagination in jsp - JSP-Servlet
Pagination in jsp  I need an example of pagination in JSP using display tag
JSP Pagination
to be shown, I want to implement Pagination.. Can someone show me a sample code which I could possibly use??   JSP Pagination pagination.jsp: <%@ page..."); } %> <html><h3>Pagination of JSP page</h3> <body><
JTable Pagination
JTable Pagination  Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement pagination for the same. Can someone please help me out with this ? I have tried out many things from
Two Pagination in one page
Two Pagination in one page  hai friends any one help me. how do u make two pagination script in same page i'm used some ajax coding one pagination script is working but another pagination is not working please help me urgent
pagination in hibernate with jsp
pagination in hibernate with jsp  Hi, plz give me example on pagination .   Hi Friend, Visit HereADS_TO_REPLACE_1 Thanks
Pagination example with html code
Pagination example with html code  Hi, could u please provide pagination code with clear cut explanation. Thanks in advance
JSF architecture
JSF architecture  What is JSF architecture
pagination - JSP-Servlet
pagination  Hi, could u tell me how i will handle pagination... friend, Simple pagination in jsp Simple pagination in JSP... Simple pagination in jsp Displaying Records
pagination in jsp - JDBC
pagination in jsp  Hi, I have millions of records in my oracle d... in advance...   Hi friend, This is simple code of pagination. Simple pagination in jsp
jsf attribute
jsf attribute  What is the different between value and binding attribute of jsf
pagination+dynamic pagesize+hibernate - Struts
pagination+dynamic pagesize+hibernate  pagination using hibernate with dynamic page size plzz heilp me
Pagination without using database in php
Pagination without using database in php  How can I show multiple images in multiple rows with pagination in php
JSF Tutorial
JSF Tutorial  plz provide the jsf complete tutorial  Hi, We have lot's of JSF tutorials. Please read it at [http://roseindia.net/jsf/][1] Thanks [1]: http://roseindia.net/jsf/  The link is http
Advantages of JSF
Advantages of JSF  What are the advantages of JSF
Implementations of JSF
Implementations of JSF  What are the available implementations of JSF
Pagination in PHP code - PHP
Pagination in PHP code  3.Pagination in PHP codeIs it possible to get the paging in PHP without database call? How will I show the image instead of numbering? any code that can help
pagination in php - Ajax
pagination in php  i want to fetch my data base in view page...i hav done pagination... i don't want the order....like... 1 2 3 4 . . . last i want the order in... 1 2 3 4 5 6 7
JSF framework
JSF framework  hi Can I use Jdeveloper to learn JSF framework? thanks Sangeetha
jsf session
jsf session  How to maintain session in jsf login application?   Please visit the following links: http://www.roseindia.net/jsf/richfaces/creating-managed-bean.shtml http://www.roseindia.net/jsf/RememberMeLogin.shtml
jsf session
jsf session  How to maintain session in jsf login application?   Please visit the following links: http://www.roseindia.net/jsf/richfaces/creating-managed-bean.shtml http://www.roseindia.net/jsf/RememberMeLogin.shtml
JSF Tutorial
JSF Tutorial  I am novice to JSF Programming. And want to learn the Java Server Faces (JSF) technology online. So, could you please list down few helpful JSF Tutorials. Also, which is the latest version of Java Server Faces (JSF
Pagination in struts 2
Pagination in struts 2  Hi, I have one question regarding pagination in struts 2 I saw one of your code that you explain here:- http... me or guide me what other option i have to use pagination in struts 2 without
JSF code
need jsf code that will populate combo box values from the database  Hi, i'm new on JSf,I need jsf code that will populate combo box values from the database when the form runs
ModuleNotFoundError: No module named 'apistar-pagination'
ModuleNotFoundError: No module named 'apistar-pagination'  Hi, My... named 'apistar-pagination' How to remove the ModuleNotFoundError: No module named 'apistar-pagination' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'codingsoho-pagination'
ModuleNotFoundError: No module named 'codingsoho-pagination'  Hi...: No module named 'codingsoho-pagination' How to remove the ModuleNotFoundError: No module named 'codingsoho-pagination' error? Thanks   Hi
ModuleNotFoundError: No module named 'codingsoho-pagination'
ModuleNotFoundError: No module named 'codingsoho-pagination'  Hi...: No module named 'codingsoho-pagination' How to remove the ModuleNotFoundError: No module named 'codingsoho-pagination' error? Thanks   Hi

Ads