• 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

How to use Ajax in JSF

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic