Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get the return value of ajax action  RSS feed

 
Ad Tan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am quite new to JSF... and have the following question (I've tried search).

I am using RichFaces' command button to send an (AJAX) action to a managed bean:

Assuming my perform method in the managed bean returns a string, how can I get the value out?

Side track abit... I'm using onbeforedomupdate because oncomplete does not seems to work (on RichFaces 3.3.2), any ideas?

Adstan
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
onComplete should work, but YMMV. I believe that RichFaces idea of returning data from AJAX requests is to use JSON. The documentation could have done a better job, but if you dig enough, I think there's examples of how to use the "data=" attribute for that.
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in this case oncomplete might not work because you might be navigating away from your current page/view.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kavita Tipnis wrote:in this case oncomplete might not work because you might be navigating away from your current page/view.

In fact, I think I can confidently say that in the case of an action processor that results in leaving the current view that the onComplete action definitely wouldn't work!

My memory has gone out on me tonight, but I think onClick or onChange would be more appropriate for making AJAX requests. There should be some examples in the RichFaces manual, though.
 
Ad Tan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright... so if my action method returns something, oncomplete doesn't work.... and also, there is no change of my presentation layer directly receiving the return value???

However, I have tried oncomplete on an action method that returns void; and it doesn't work as well.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ad Tan wrote:
However, I have tried oncomplete on an action method that returns void; and it doesn't work as well.


That's because the problem is that when you return an unmapped navigation (including void), JSF simply redisplays the same page.

Note that word: "redisplays". It's important. JavaScript can't act after you've left the current page even if it's only to reload an identical copy (redisplay) of the current page!

The problem isn't JSF-related. It's endemic to HTML+JavaScript. Unless you do an AJAX submit, the entire page will be discarded and replaced by whatever comes back from the server when the action is executed. And, since HTTP is request/response (even in AJAX), there will be something coming back from the server.
 
Max Katz
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just make the perform method void or return null and it should work.

Max
http://mkblog.exadel.com
 
Ad Tan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found the solution to both my questions.

The reason why things do not work is, the guy previously working on this project added a JS prototype class with the name "Node", which somehow conflicts which RichFaces.

After renaming that "Node" class to something else, my oncomplete could work.

Based on this, I could use directly get my bean value out with my oncomplete method.


Thanks for all the help...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!