I am trying to do jsp pagination, I loooked all over but didnt find any example that shows the way I want to do it. In my program I am loading data from oracle table using package. I have a package that has procedure loaddata, which is called from javabean load function. Curently all the data are dumped to jsp page from javabean, some one has a example I can look at it to change it into multiple pages. Thank you
Where can I find JSP pagination examples?
Quick and simple answer, use this:
http://www.datatables.net/
It's a lovely scrollable/paginating table, which has third party plugins which allow editing. It's pretty easy to setup, and the website has lots of examples and an active and helpful forum.
From a database perspective, you'll need to consider accepting the following parameters to your queries:
Rows per page
Current page
The DBA in my company splits this into two queries I need to call:
Give me all the values for page 1, with 10 rows per page.
Give me the maximum number of pages that are possible (don't actually return any values.)
Related
I have found the Jquery datatables plug in extremely useful for simple, read only applications where I'd like to give the user pagination, sorting and searching of very large sets of data (millions of rows using server side processing).
I have a system for reusing this code but I end up doing the same thing over and over alot. I'd like to write a very generalized api that I essentially just need to configure the sql needed to retrieve the data used in the table. I am looking for a good design pattern/approach to do this. I've seen articles like this http://www.codeproject.com/Articles/359750/jQuery-DataTables-in-Java-Web-Applications and have a complete understanding of how server side processing works (have done it in java and asp.net many times). For someone to answer you will probably need to have a deep understanding of how server side processing works in java but here are some issues that come up with attempting to do this:
I generally run three separate queries. A count without the search clause, a count with the clause included, the query for the actual data. I haven't found an efficient way to do all 3 at once and doing so requires a lot of extra data to come back from db (ie counts over and over). The api needs to support behavior based on these three different queries and complex queries at that. I generally row number () over an index for the pagination to be relatively speedy with large data.
*where clause changes dynamically (user can search over a variable number of rows).
*order by clause changes for the same reason.
overall, each case is often pretty specific to the data we need. Is there a good way to abstract this so that I can do minimal work when I want to use the plug in server side.
So, the steps are as follows in most projects:
*extract the params the plug on sends to the server (alot of times my own are added, mostly date ranges)
*build the unfiltered count query (this is rarely dynamic).
*build the filtered count query (is dynamic)
*build the data query
*construct a model object of the table and return it as json.
A lot of the issues occur setting the prepared statements with a variable number of parameters. Dynamically generating the sql in a general way (say based on just column names) seems unlikely. I am wondering if someone else has created something they are using for this or if it sounds like a specific pattern is applicable. It has just occurred to me that creating a reusable filter may be helpful in java. Any advice would be greatly appreciated. Feel free to be language agnostic as the architecture is what I'm trying to figure out.
We have base search criteria where all request parameters relevant to DataTables are mapped onto class properties (fields) and custom search criteria class that extends base and contains specific to business logic fields for sutom search. Also on server side we have repository class that takes custom search criteria as an argument and makes queries to database.
If you are familiar with C#, you could check out custom binding code and example of usage.
You could do such custom binding in your Java code as well.
What is the proper but simple way to display and edit SQL table on JSP pages, having all the SQL and Java code in Servlet?
Coming from ASP.NET environment, I'm looking for GridView substitute - to display editable rows on JSP page but have all the SQL methods in Servlet file. My goal is to have 2 JSP pages: 1st for simple table display, 2nd as a CMS to edit these rows (save button for every record), and a Servlet with most of the Java code.
I would appreciate some simple example to display editable table in JSP, with Java/SQL code in Servlet. I've seen some bits and pieces online, but each one is using different approach. It would be best not to edit any server settings.
Thanks in advance.
You could evaluate DisplayTag with input elements in it.
As far as simple JSP is concerned, there is no such control as GridView in ASP.NET.
You can try JSF based controls like DataTable (http://www.mkyong.com/jsf2/jsf-2-datatable-example/). But it does not have any in-build editing functionality like GridView. Datatable will provide you enough control over it so as to implement your own edit/delete/add logic.
To start with JSF, refer this http://www.mkyong.com/tutorials/jsf-2-0-tutorials/ or http://www.vogella.com/articles/JavaServerFaces/article.html
I would suggest using jqGrid.
It is sort and simple plus all you have to do is mapping your CRUD url to controllers where you do the the SQL operations.
http://www.trirand.com/blog/jqgrid/jqgrid.html
I want to do a content search in my database. And the requirement is it has to be like a google search completely based on Ajax. Can you guys suggest me any framework or architecture or any kind of idea?
Example:
Employee Table contains Employee First Name, Last Name , Middle Name and Email. I have to search the table by providing any one of the field and the details of that employee should be populated
Consider using an index-based search engine. Apache Lucene is immensely popular, high-performant and well documented.
There are different parts to your question:
1) Ajax library: you could use Jquery which provides simple ajax methods http://api.jquery.com/jQuery.ajax/
2) On the server end there are a couple of options depending on the type of database youre using. Is it relational, is it nosql? Is your choice of database flexible or is it set in stone?
Lucene provides a query language for an index with more complex information and search requirements. But if your use case is as simple as the one above, you might just shoot off different SQL queries (assuming your database is relational).
I have a problem that is common, but I am not quite sure exactly how do go about solving it.
My situation is I have a form that will have a drop down of States. I also have a drop down that should have military installations(bases), but the bases that are populated are dependent on the value of the state dropdown.
In my database I will have a table BASES such as the following most likely.
BASES Table
int base_id
varchar state
varchar base_name
varcar city
When a customer selects a state, I need to query all the bases in that state. and return them and populate the bases drop down. I am well aware that I can do this easily by just posting the data to the server as form data, but I would rather find a simpler solution and I know ajax is used to solve problems like this one.
I am entry level, and ajax is a new topic for me so any help I can get would be appreciated.
I am using Java/JSP/Servlets and am using MySQL.
If you think that AJAX is the solution, and you're using Java, then check out DWR. It allows you to trivially expose Java objects in Javascript. You can create a server-side object to derive your list of data for pull-down menus and easily expose this in Javascript.
This can all be solved with javascript alone if you hardcoded the state/base relationship into an array(s) in the javascript file.
Here is an example I found on the internet.
http://www.javascriptkit.com/javatutors/selectcontent2.shtml
Ii have a txt file which contains 2000 rows of data. I want to retrive this data and dispaly in a table form, but i want show some 20-30 records per page and rest numbering the pages like in google.
How do you achieve this in jsp.
After reading the article linked by Jon, you can use Displaytag which has built-int paging functionality
You need to look into pagination using JSP, there's a tutorial that I found from this great search engine called Google:
http://www.javaworld.com/javaworld/jw-07-2004/jw-0726-pagination.html
It will talk you through the process.
This question is asked a few several times before here. Just checkout under each the tags pagination + jsp. I've answered this topic: ResultSet to Pagination. You may find it useful as well.
DisplayTag is another alternative, but it is not memory efficient as it caches all the rows in Java's memory, which might blow if you have thousands of rows and/or thousands of concurrent users. In such case better go ahead with DAO/database-level pagination, as outlined in my answer in the linked topic.