Editable SQL GridView using Java JSP and Servlet - java

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

Related

Pass data from editable HTML table to servlet

So i have a JSP page, that contents editable table with checkbox in each row, the question is, how can i pass the data from selected rows to servlet?
Can i pass it as a parameter, or get html code in servlet to parse it and get selected data?
Thank you.
Your question needs some more specifics. But here is a perfect example of how to implement editable tables:
https://code.google.com/p/jquery-datatables-editable/
It is very easy to implement and basic knowledge of jQuery will help you play around as much as you like. It even shows examples of how to use data at Java servlets.
It depends on when you want pass the values to the servlet. If you want to make all the selections and then submit, a html form submit will be the best option. once you submit the form, the data will be available in request.getParameterValues('names'). If you want to send values immediately after user selects, then you can use ajax through an onchange event

Remembering Checked Checkboxes using Display tag pagination

I actually want to accomplish the same thing a user in
Remembering checked checkboxes across pages - what's the best way?
asked. But not for php, I want it for java(Spring Portlet) and javascript.
I`m using pagination display tag and want to remember the checked checkbox while the user is navigating over the pages provided by pagination.
Have you used the org.displaytag.decorator.CheckboxTableDecorator, which will add the Checkboxes to your paginated list. It requries two fields, Id and FieldName. Id should be one of the class member of the respective bean class, and you can give any FieldName to the field. You have to include this inside a form element. And the same form name has to be given in the DisplayTag's form attribute.
Please see the displaytag examples link for help

Recommendations on Updating MySql database from Checkbox values in a HTML

I'm having a table with the contents retrieved from my MYSQL DB. Now, below the TH row I have a row for searching through the table column wise. I have shown a sample search through the table.
The user of this application might check some checkboxes after doing some search (and according to some rules that satisfies research requirements). Now, I would like to have a submit [update records] button below this table which on clicking updates the corresponding records - against which the checkbox has been selected to update the value of CheckBox column - "Accepted"in this case.
For you information, I'm using struts and so to do this I will have write a struts action class to handle this. I also considered AJAX to update this asynchronously in the back-end. I would like suggestions from people on the best practice to do this.
Given the stack you have described, you have a web application with Struts on the server. When a user chooses to update the records you can either post the data using a html form, or use Ajax calls. Irrespective of how the data is sent, you will have Struts code to process the information and update the database. The only difference is in how the data got there. It's up to you to decide which makes more sense.

How to dynamic edit a table using a JSP?

I'm trying to set delete buttons on each row of my table in order to let users to delete some rows of the table. However i'm having a terrible time to remove this rows dynamic and remove the data from database... ( no idea how to use the button onclick from html with jsp )
I decided to use some javascript inside the Jsp which did the tricky to remove the row but now i can't delete the entry from the database...
I would like to know if there is anyway to delete data from the database using the javascript and what should be the easiest way to do it ?
If you want to use JavaScript then you'll need to send an AJAX request to your server and then remove the row from the view upon success of the previous action.
For an easy and simple approach to AJAX you can try PrototypeJS. However, if you'd like to have really fancy dynamic features you may be more interested in jQuery.
Without knowing more from your project, I'd suggest to use a Servlet in the server side to receive the AJAX request.
I would like to use Ajax with div and InnerHTML. Onclick to the Remove button I will one javascript function which will make a call to server with unique id to delete the record from database , when we get response back I will hide innerHTML representing that row based on div Id.

JSP pagination from javabean

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.)

Categories

Resources