java jstl populate table data using ajax - ajax

i implemented a java ee webclient in spring framework. it reads data from a webservice and display records in a table format. on this table, im able to a delete multiple record by selecting the checkbox.
currenty im refreshing the table records using meta refresh. reason is because javascript timer refresh will bring the page to top. it affects the user experience when he/she is viewing record.
when a user select records to be deleted and click delete, a javascript confirm dialog box popup. the problem with using meta refresh is im not able to stop the refresh when the confirm dialog box popup. i tried jquery but it didnt work.
im thinking of implementing ajax to retrieve the records for the table. but how can i implement it efficiently. the records in the table are dynamic.
to add further, i have multiple html tables. for example,
#table 1
<table><tr><td></td>....</tr></table>
#table 2
<table><tr><td></td>....</tr></table>
#table 3
<table><tr><td></td>....</tr></table>

I suggest that you use a JSP as a template. This means that the body of the JSP contains static elements such as HTML code, forms and tables, while you can use tag libs to insert the dynamic data. In your case the data from the database record.
<c:forEach items="${listOfRecords}" var="item">
<table>
<tr>
<td>
<c:out value="${item}"/>
</td>
</tr>
</table>
</c:forEach>
Then using a servlet you can send this in the response to the client. The AJAX call will receive the response and append the HTML to the current table. In the code snippet below AJAX sends the data ("recordid="+id) in a request to the servlet located at /approot/myservlet. When the servlet receives the request it retrieves the record id from the request, deletes the record from the database, retrieves any new records add since the last query, passes the new records to the JSP via a request dispatcher, the HTML table containing the new data is generated and sent as a response back to the browser. The javascript in the success attribute is launched and the response which is contained in the msg variable is appended to the current table.
$.ajax({
type: "post",
url: "/approot/myservlet",
data: "recordid="+id,
success: function(msg){ $('#table1').append(msg);
});
This is just a quick overview of what I imagine is your solution. You might find the step by step guide I wrote about how to set up a J2EE application using a web service, JSP, Servlet, tag libs and AJAX.

I would remove the page refresh and use AJAX. This is how I imagine you should approach this problem. An AJAX call is made at regular intervals (using a timer) to a servlet that queries a database for the records added since the last such query. The records returned are formatted into HTML using a JSP template and tag libs and sent in the response to the client. The AJAX receives the response and appends the HTML to the appropriate table. To stop the AJAX from making a call to the servlet you could stop the timer just before showing the popup box and restart it when the page is updated with the records deleted.
EDIT: You could identify each table with an (id="table1") and in then you can append that HTML to the right table.

Related

How to secure data in html select object filled with Ajax from MVC database

sorry for my english
I am filling the select element with values ajax from the database. Then I want to verify that the data that changed when the user posted the form as a result of changing the value values of the select object through the browser is really the data I filled.
How can I solve this with a general coding in infrastructure?
Instead of going to the database and checking each filled data one by one, I want to hold the data I filled in the select tag and check the verification with this data in the post operation.
mvc fill select changed value example

joomla dynamic drop down on registration form

I have two drop down list on my registration page of sql type. they both fetch data from database. but my problem is that in second drop down list , i want specific data as per the option selected in dropdown list 1. how to do it?
thank you very much
There are two possibilities(well theoretically endless)..
1) You send the whole data on pageload and then filter it using javascript based on the first selection.
2) Use the ajax technique, where you send the ajax handler the selected value and then the handler queries the database and sends the relative data which you append on the second select in the runtime.
Note:- for larger tables the firstone is NOT Recommended.

Grails update html table ajax insert with message

I'm come from a .net background to grails. I got a form for user to insert, and a html table with the list of records. Once user insert a new record, how do I update the html table with the record and display a message - e.g. company inserted?
Create a domain class for inserting your records, with whatever properties you need. Read Creating domain class and Grails GORM
Once the user submits your form insert the necessary values as a record into this. For getting the entire list of records you can call the list() method on your domain-class. Send the entire list of records to the client side as the response of the action / render as a model. See render. Update your html table using these new records.
For the status part, you may want to do the insert operations in a try-catch block and render a status a message accordingly.

Server-side and AJAX and data manipulation

I'd like to get a census on methods of removing/adding records via AJAX and updating the front-end.
For tabular data (take an inbox for example):
When I want to remove that first message, where/how should I be referencing the ID of that message and sending it to my AJAX call? I've seen some people put the ID in a hidden field, or use the checkbox id attribute...
How is this transaction properly handled so that when my call is successful, I can "remove" that row with jQuery?
What I typically use to "attach" data like this to HTML elements is to use the HTML5 data attribute. This will allow you to store multiple pieces of data for use w/ Javascript/jQuery/Ajax, without doing anything "hacky" like embedding stuff in IDs or having to parse out values.
For example, in your case of a table row, you could have something like this:
<tr data-email-id="123"><td>...</td></tr>
Then it would be simple to reference in your jQuery (assume $(this) references the tr):
var emailId = $(this).attr('data-email-id');

How to Bind Data coming from DB to spring input tag

i have the following scenario.
I have a list of auctions coming from the DB. I am displaying each auction properties on the JSP page as a record.
I am using spring 3.0.5, Tomcat 6.0.29 and eclipselink as JPA provider.
In my controller i am seeting this list as model attribute and passing it to the JSp page.
I want to use spring tags (form:input) to display the data.
Using Form backing bean we can display default values on a form. But in my case is there any way to bind data to form:input tag in the JSP?
Thanks
There is no reason to display your data in form:input tags other than that you want to allow your user to edit the data. If that is not the case, then using form:input just to display the data is pointless.
If you want to allow your user to edit the data, how are you going to get back the changes he has done? Obviously you are going to need your Command object. So there is no reason not to use formBackingObject() in your FormController to set values in your Command object, which will be consequently displayed on your JSP. When user will make any changes and submit the form, you will get all those modified values in your Command object which you can process in onSubmit() method of your FormController.

Resources