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?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Giorgio
  • 1,073
  • 3
  • 15
  • 33
  • 1
    Yep, I think you can do this using `.load()`. Just bind a action to a very simple JSP with just the tag and the minimum includes required. The server will render a html response. Get it with `.load()` and replace the old table. – TCHdvlp Jul 15 '14 at 13:19
  • Thanks very much for your quicky reply @TCHdvlp. So basically I have to make a jsp with containing just the tag and then create an action that load this jsp, so I can refresh the table using something like this: `.load("refreshTable.action");` – Giorgio Jul 15 '14 at 13:34
  • 1
    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. – TCHdvlp Jul 15 '14 at 13:40

1 Answers1

1

Try this.

$.ajax({
   type:"POST",
   url:"yourpage.jsp",
   data :{ yourdata : yourdata },
   success: function(data) {
   }    
});
$(".yourtableClass").load("yourpage.jsp .yourtableClass", { yourdata : yourdata });
Arun
  • 684
  • 1
  • 14
  • 25
  • 1
    this is making 2 ajax requests and the first one does nothing with the reponse....makes no sense – charlietfl Jul 15 '14 at 13:21
  • If ha wants his table to be reloaded or re-populated, he must bind `.load()` with a `anyAction.do` and not simply the jsp. – TCHdvlp Jul 15 '14 at 13:21
  • @TCHdvlp `load()` is simply a convenience method of `$.ajax`. There is never a case wher you `must use it` – charlietfl Jul 15 '14 at 13:23
  • The last line .load will refresh only the table contents. which happens after the request. This will work fine. – Arun Jul 15 '14 at 13:24
  • 1
    @Arun there is no need for 2 requests, use one or the other method shown, not both – charlietfl Jul 15 '14 at 13:25
  • @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. – TCHdvlp Jul 15 '14 at 13:27