• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to call a servlet from JSF without using dispatch(url)

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am working on a task where i have to generate and display reports in the same page when the user clicks Run Report commandButton.

In a servlet i wrote all the jasper coding to generate the report.
To call sevlet from my jsf page i used a method called callMyServlet().
In callServlet method i have used context.getExternalContext().dispatch(url) to call my servlet.
In my JSF page i called callMyServlet method in action of a commandButton
This generates the report but not in the same page.

I would like to know how to call my servlet from jsf without using dispatch url

Code of servlet


Code of callMyServlet Method




JSF Code of commandButton




I have mapped my servlet in web.xml

Please help me out how to get my task done.
any sample code will also help.

Cheers,
Sreelekha
 
Saloon Keeper
Posts: 28486
210
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
"JSF" isn't a control program - it's a way of managing web pages. When you request a JSF page, you're requesting a document that's been designed according to JSF standards that will be converted to HTML via the JSF servlet. On the inbound end, the JSF servlet recieves data from that HTML page and uses it to dispatch the next page view, once again using the JSF rules and resources.

If you want a report to display on a JSF page, you have to use JSF resources to ensure that the page is managed correctly. Furthermore, servlets aren't really intended to be "called". The normal process to get a servlet to get another servlet to do work for it is to forward the request. You could then forward the results of that to the JSF servlet, but considering all the side aspects, you'd probably lose important things in the process. It's usually better to simply have the reporting servlet be a reporting servlet and just place it alongside the JSF stuff the same way you'd do with non-JSF stuff.

In other words, JSF isn't all-or-nothing. Your life will be simpler if your webapp only uses JSF functionality on the aspects of the app that work best on JSF. For the most part, things like servlet-generated reports should just be themselves and not try to be JSF.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...

I'm sorry for "revive" this topic... but I'd like to know a example of using Jasper Reports and JSF in that way cited?

I'm having a lot of errors using "context.getExternalContext().dispatch(..." in a Managed Bean filter that call a report.

Best regards!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic