• 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

Get the return value of ajax action

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic