refresh displaytag table using ajax
Asked Answered
M

1

7

Hy guys,

I'm trying to solve this problem:

I have a jsp page with inside a table generated with dispaytag library and other kind of stuff.

When I press a button, I would like to generate an ajax call reloading just the table and not the whole jsp page, that display correctly the uptated table with also the generated tag pagebanner and pagelinks properly, increasing and decreasing elements founds.

Is there any solution to solve this problem?

Model answered 15/7, 2014 at 13:16 Comment(3)
Yep, I think you can do this using .load(). Just bind a action to a very simple JSP with just the <display:table> tag and the minimum includes required. The server will render a html response. Get it with .load() and replace the old table.Rourke
Thanks very much for your quicky reply @TCHdvlp. So basically I have to make a jsp with containing just the <display:table> tag and then create an action that load this jsp, so I can refresh the table using something like this: .load("refreshTable.action");Model
Yes, you must specify in your struts-config that this action leads to this jsp page. When you'll call this action through ajax, you can add as many parameter as you want in the url and get them in the action via HttpRequest.getParameter(). at the end of the action, it will simply render the page but wont redirect you as you will catch the response with javascript. Don't forget to include taglibs in your jsp.Rourke
R
1

Try this.

$.ajax({
   type:"POST",
   url:"yourpage.jsp",
   data :{ yourdata : yourdata },
   success: function(data) {
   }    
});
$(".yourtableClass").load("yourpage.jsp .yourtableClass", { yourdata : yourdata });
Redbreast answered 15/7, 2014 at 13:20 Comment(6)
this is making 2 ajax requests and the first one does nothing with the reponse....makes no senseDorren
If ha wants his table to be reloaded or re-populated, he must bind .load() with a anyAction.do and not simply the jsp.Rourke
@Rourke load() is simply a convenience method of $.ajax. There is never a case wher you must use itDorren
The last line .load will refresh only the table contents. which happens after the request. This will work fine.Redbreast
@Redbreast there is no need for 2 requests, use one or the other method shown, not bothDorren
@charlietfl, I neverd said he must use .load() instead of $.ajax, oO, I did ?? Mwell, I just say that the url must be the action.do and not the jsp.Rourke

© 2022 - 2024 — McMap. All rights reserved.