This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to imbed servlet in JSF

 
Sookhee Belmont
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to JSF, and sweating to find a to connect servlet files to JSF.
I have several servlet files to produce a JSF output. The servlet files do the necessary calculations to make the output. It is not realistic to write it into the bean file. Is there a way that I can use/connect these servlet files to make a JSF output?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet files do the necessary calculations to make the output.

Turn your servlets into regular java classes(business objects), removing any HttpServlet specific code, and call those classes from your managed beans.
 
Sookhee Belmont
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Gregg, for your reply. I am just out of college with very limited experience in programming with 4 days in JSF, so I have to ask you further help. Could you please explain it more in detail?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic idea is that your managed beans collect page data and process events. Any business logic like db lookups/queries, calculations, data processing, etc should occur in "helper classes" or "business classes". This is true whether you are using JSF, some other web framework, or simple Servlets/JSP development.

If you are already doing this stuff in your servlet, turn the servlet into one of these helper classes that you call from your managed beans. If all the servlet is doing it gathering data and redirecting to other pages, just trash the servlets. They won't do any good in JSF.
 
Sookhee Belmont
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Gregg,

This is the intention what I am trying to do with this topic. Could you please look it up to give me your opinion. I am having problems in passing bean parameter that is initiated in File1.jsp. The parameter goes thru the bean file and I should recover the parameter in File2.jsp.
When I post it using <form><input ... ></form>, I do not have any problem to open it inside the code block in File2.jsp. But when I try to the same thing using a JSF tag, it never goes thru. It is null when I tried to get it in File2.jsp.

Thank you very much in advance.

Sookhee
<%@ page language="java" import="moon.bean.MoonBean" %>
<html>
...

<body>
<f:view>
<%
// MoonBean time1 = (MoonBean)pageContext.findAttribute("time");//null
// time1.getTime(); // null -->error

// does not work either
// FacesContext fc = FacesContext.getCurrentInstance();
// String time1 = fc.getExternalContext().getRequestParameterMap().get("time");

String time1 = request.getParameter("time");
// String time1 = request.getParameter("moon.bean.getTime()");
if(time1==null)
out.println("time is null");
%>
<h utputText value="#{MoonBean.time}"></h utputText><!-- works good -->

</f:view>
</body>
</html>
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in ur faces config xml, set the bean-managed-scope to session.

<managed-bean-scope>session</managed-bean-scope>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic