Win a copy of Mastering Non-Functional Requirements this week in the Design forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet, managedBean and JSF (generate report)  RSS feed

 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need help in the following:

I want to generate report that is from iReport using Eclipse, I create the Servlet class, managed Bean and I have my jsp
In side the Servlet class I have this method:



now in the managedBean(MB)  I whant to call the servlet, How i can do that? and how I can use the RequestDispatcher?

I have this method in the MB but is not completed tell now:




RequestDispatcher dispatcher = request.getRequestDispatcher("/GetName"); >>> what I have to put in /GetName place ?


In jsp:


Thank you in advanc.
 
Tim Holloway
Bartender
Posts: 18605
68
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF works best when it's used with HTML forms.

I recommend that you use a servlet to generate the PDF document. Servlets and JSF can communicate easily, since JSF session-scope objects are simply JSF-managed JEE session objects.
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replay. I solve it but now how I can print the parameter in the Servlet class to make sure that the parameter come from the user?
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In this method "doPost", I want to print the value of the parameter to make sure that every thing is fine, because the report now open for me and it is showing the data but without the parameter, I thing the report in iReport dose not receive any parameter to make any filtration.

Any help or comments!

Thank you in advance.
 
Tim Holloway
Bartender
Posts: 18605
68
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That will record the value of the end date in the server log.

For example, a URL like this:

http://localhost:8080/myreportservlet?endDate=2016-09-08

Should produce the message

Request Data parameter value was 2016-09-08

And if the parameter was omitted from the request URL, you would see

Request Data parameter value was null

 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you for your help, after I printing the parameter I found that the value is null so that is the reason for the empty report. So any one know why the servlet received empty value of the parameter?

Thank you.
 
Tim Holloway
Bartender
Posts: 18605
68
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request scope is almost entirely useless in JSF, so what you probably need to do is make "endDate" be a session-scope object.
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:Request scope is almost entirely useless in JSF, so what you probably need to do is make "endDate" be a session-scope object.


How I can make "endDate" be a session-scope object?
 
Tim Holloway
Bartender
Posts: 18605
68
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can obtain the HttpSession object via the FacesContext and create/read the date as an independent object. OR you can define a JSF Managed Bean in session scope and make the endDate be one of its properties. Which is probably more useful, since then the endDate can be entered in a JSF form by the user.

JSF session scope is exactly the same as J(2)EE session scope, so your servlet merely needs to retrieve the object whose name matches the JSF managed bean name,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!