• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use Ajax in JSF  RSS feed

 
Dwijen Bhattacharjee
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to know how can I use Ajax in JSF. For my application for the time being I created a servlet for handling the request and sending the response.But for that I am using HttpServletRequest and Response objects which I don't think is a good practice.
Can Anyone tell me how to replace the servlet and use any managed bean to handling the request and response.
It will very helpfull to me if you can provide any code snippet.

Thanks in advance.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest and cleanest way is to use a JSF taglib that supports AJAX, such as RichFaces. RichFaces handles all the request/response stuff for you, allows you to mark what elements of the page will be sensitive to AJAX updating, significantly cuts down on the client-side JavaScript code you need to right, and automatically handles the differences in JavaScript implementations between different browsers and browser versions.

With RichFaces, most of the magic is in the JSF tags, so little, if any AJAX-specific code has to be provided in the JSF backing beans and there's no need for custom servlets.

AJAX ultimately does do everything in terms of Http Request and Response objects even for non-Java AJAX apps. That's the only way you can communicate with an HTTP server, so you're not doing anything "wrong". However, why code and debug a lot of complicated stuff if someone's already done the really ugly stuff for you?
 
Dwijen Bhattacharjee
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to use Ajax in 2-3 pages in my application and i do not want to use Richfaces. Right Now I have created a Servlet and calling that servlet and getting respons. But I don't think it is good way to do . Please tell me how can i handle ajax request in JSF . Can I do the same from any managed bean. If possible ,How?
 
Zack Marrapese
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should seriously consider using RichFaces. They do an excellent job of it, and there is no real reason to re-invent the wheel. You will end up spending a ton of time and the result will be inferior to richFaces/ajax4jsf anyways...they have been working on this project for years.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!