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.
"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.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.