Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
sree lekha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
André Campanini
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!