• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AJAX handle struts success/failure

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to AJAX and trying to understand the concept.

I've a struts 1.1 action class that takes its input , does some biz op and returns a mapping.findForward("success or failure").

Now, when I invoke the struts action via AJAX , I also provide a callback which will invoked upon server returning a response. I want to understand what happens when the server responds, because, based on the struts configuration xml, the response will be forwarded to the corresponding JSP. If thats the case, whats the use of the callback method? Should I ignore that?

Thanks

Vijay
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Ajax callback method has absolutely nothing to do with stuff that goes on one the server, such as a forward. It will be invoked when the response is returned to the browser. It is completely independent of whatever struts (or anything else) is doing on the server.
 
Vijay Ganapathy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the UI is going to be painted by whatever the JSP that the struts forwards to, isn't it?

Basically, I'm trying to AJAXify an existing server call(struts 1.1) that in turn invokes 3rd party web services.
When the result comes back , based on current struts config, it is forward to a different JSP.
So, my question is, what is the point of implementing a callback in the calling JSP which will probably never going to get executed?

Here's the scenario:

JSP1 {
<form id="xx">
inputs x, y, z;
</form

<script language="javascript">
function callServer() {
makeAjaxCall();
}
function callback(response) {
//deal with response
}
</html> //end jsp1

But based on what is in struts config, the response is forwarded to a JSP2.
So, what happens to the callback(response) in JSP1?
JSP2
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vijay Ganapathy wrote:But the UI is going to be painted by whatever the JSP that the struts forwards to, isn't it?


Yes, and the HTML page that is generated by that JSP is what is returned as the response. You do understand that JSP operates on the server, right?

So, my question is, what is the point of implementing a callback in the calling JSP which will probably never going to get executed?


It's going to get executed. Why do you think it will not be? If you don't have anything to do when the response returns, then don't implement the callback. But to think that it's somehow not going to get executed if declared is flat-out wrong.
 
Vijay Ganapathy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so, from a flow standpoint

User Click -> Javascript -> AJAX request(server response will not be processed here since callback not implemented) -> Server process -> different URL

Is this correct?
 
author
Posts: 297
5
Android Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the point of making an AJAX request to load a different URL? The whole point of AJAX is to avoid loading a whole new page. It's not clear to me what you're trying to do here.
 
Vijay Ganapathy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It's not clear to me what you're trying to do here.



Well.. to display a progress bar to the user on the current page but still the response has to be shown on a different page

This is already a mature struts web app , so I don't want to go around re-engineer a whole lot to display the result in the current page.

So, I'm just wondering if there's a way at all to redirect the response. This might not be possible since all I have is JSP generated HTML in the callback method.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vijay Ganapathy wrote:Well.. to display a progress bar to the user on the current page but still the response has to be shown on a different page


Huh? What does a progress bar have to do with another page? A response can only go one "place" -- and using Ajax, that isn't a new browser page.

So, I'm just wondering if there's a way at all to redirect the response. This might not be possible since all I have is JSP generated HTML in the callback method.


As I already pointed out, JSP or not is completely moot.

Maybe you need to back up and explain what you are actually trying to accomplish without any decisions as to how to go about it?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you want to mimic the server behavior(forwarding to the other JSP) in the AJAX callback method.
The data that you will have in the call back function is either html(response from the server as a result of the JSP execution) or xml depending on the response type which you can use to update the page.
You may be able to potentially redirect the request in the callback function since it is just javascript possibly using window.location.href.
You need to be diligent about any request data to the other URL.

But yeah, the exact scenario needs to be explained
 
Vijay Ganapathy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maybe you need to back up and explain what you are actually trying to accomplish without any decisions as to how to go about it?




What I'm trying to do is pretty usual stuff.
I've a JSP page with a form and a submit button in it. On clicking submit, it takes the form data and posts it to the server(struts 1.1) which in turn invokes a 3rd party web service.
The problem is that when the web service takes some time to respond, the users are quiet often clicking on the submit button more than once which is triggering off more requests.

Now all I wanted to do was provide the users some feedback while blocking the user actions.

I am currently displaying an animated gif on form submit, but once the form is submitted IE is stop the gif animation. So, I thought of AJAXifying the request so that the gif animation could continue.
But in fact, I couldn't do that because I had to show the response in a different JSP page that has much more functionality. (I just picked a wrong use case for AJAX).
Also, now, I don't need to do that since I'm able to run the gif animation by displaying the gif once again after the form submit which I'm doing using JQuery. Let me know if you have any better ideas.

This is what I've done:





 
reply
    Bookmark Topic Watch Topic
  • New Topic