Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax asynchronous behavior issue.

 
Saurabh Pol
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17639
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saurabh Pol
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17639
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic