my dog learned polymorphism*
The moose likes JSF and the fly likes How to imbed servlet in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to imbed servlet in JSF" Watch "How to imbed servlet in JSF" New topic
Author

How to imbed servlet in JSF

Sookhee Belmont
Greenhorn

Joined: Apr 18, 2006
Posts: 3
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

Joined: Jul 11, 2001
Posts: 15290
    
    6

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.


GenRocket - Experts at Building Test Data
Sookhee Belmont
Greenhorn

Joined: Apr 18, 2006
Posts: 3
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

Joined: Jul 11, 2001
Posts: 15290
    
    6

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

Joined: Apr 18, 2006
Posts: 3
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

Joined: Aug 25, 2005
Posts: 536
in ur faces config xml, set the bean-managed-scope to session.

<managed-bean-scope>session</managed-bean-scope>


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to imbed servlet in JSF
 
Similar Threads
Good Books to learn basics of JSF
How to generate real excel reports
Download file from database
jsf in a jsp:include doesn't work?
Corrupt PDF Files