wood burning stoves 2.0*
The moose likes JSF and the fly likes Ajax asynchronous behavior issue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Ajax asynchronous behavior issue." Watch "Ajax asynchronous behavior issue." New topic
Author

Ajax asynchronous behavior issue.

Saurabh Pol
Greenhorn

Joined: Dec 05, 2012
Posts: 12
Hello Experts,

I am using JSF a4j:JavaScript .

I am calling it from JavaScript .
my call to a method sets one sequence ID from database to bean.
and after my JavaScript execution use that sequence ID.

but problem is my JavaScript execution is not waiting for the Ajax call to complete,
it just calls the a4j:function and execute the rest of JavaScript code, so its failing.

Can you please help me to get out of it.

Thanks and Regards,
Saurabh Pol.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

That's why they call it Asynchronousp JavaScript Execution (AJAX)!

If you are using Richfaces, then you get the jQuery JavaScript library "for free". It's not the most up-to-date version of jQuery, but it's enough that you can use it to code your update as a synchronous operation.

Although realistically, you are probably not using RichFaces properly. More commonly, you'd break the code into 2 parts and let RichFaces manage the before and after. For example:


This also scales up to server-side action processing if you add an action= attribute.


Customer surveys are for companies who didn't pay proper attention to begin with.
Saurabh Pol
Greenhorn

Joined: Dec 05, 2012
Posts: 12
Hi Tim,

Thanks for your reply.
I can not separate the JavaScript into two parts,
because it is the script for event handling and within it I have many conditional checks.
and the script is designed for drag drop options so if I apart java script code I could miss the flow.

So I want to get the solution for it that the JavaScript execution should wait until it finishes Ajax call.
Please let me know is there any property or anything else can help me.

Thanks and Regards,
Saurabh Pol.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

If the script needs to wait until the AJAX call has returned, then it is the script's responsibility to do the waiting. Otherwise the script is defective and will not work properly whether you are using JSF or not.
 
Don't get me started about those stupid light bulbs.
 
subject: Ajax asynchronous behavior issue.
 
Similar Threads
How to populate dependant <html:select>
Permission Denied Error
Parallel requests using AJAX
Ajax call is not invoking properly ?
How do I achieve this solution?