File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Integerate JSF,servlet and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Integerate JSF,servlet and JSP" Watch "Integerate JSF,servlet and JSP" New topic
Author

Integerate JSF,servlet and JSP

Abhilash Sharma
Ranch Hand

Joined: Dec 05, 2010
Posts: 67

HELLO

I am just a beginner at JSF So I didn't know whether it is right question.
Is it possible that If I make a form with JSF tags/components and define a servlet for action attribute (i.e can form data submitted to a servlet) and if yes then How can I achieve this and How can I get form parameters in servlet. Is it same as request.getParameter() of method or anything else.
Please explain.
I am going to make a project for my self practice and want to use JSF,SERVLET AND JSP all together.

Thanks


OCPJP 6 | OCEJWCD 6
Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 162

Form data submitted from a JSF form with a JSF commandButton gets sent to the managed bean you specify in the input fields. I'm no expert but as far as I know you can't directly access a servlet using JSF components. Why are you trying to mix all three anyway? I would recommend using Servlet and JSP seperately to learn request/response as JSF is built on top of Servlet. Once you get a grasp of that then start using JSF. I have only started with JSF myself after using servlets and JSP for some time. Knowing the latter helped my understanding when I started with JSF.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

JSF Views (forms) are always sent to the FacesServlet. The FacesServlet is self-contained and only rarely subclassed - not something that you should be doing at beginner-level. In fact, not something I've needed to do in 6 years working with JSF.

A JSF app can have JSF Views, JSP pages and Servlets, but the JSPs and servlets don't directly interact with JSF View definitions. They can, however, share data, since a JSF session- or application-scoped ManagedBean is the same bean as a servlet/JSP bean of the same name/scope. All the ManagedBean facility does is automate the creation of that bean on demand by JSF without the need for user coding.

I actually don't recommend attempting to mix JSP, servlet and JSF in a single app if you are a beginner. Not until you need to do non-JSF things like create PDFs or Excel files. Concentrate on one venue at a time until you know how it works and how it interacts with JEE in general.

Also, be careful with old documentation. In JSF Version 1, the View Definition Language was JSP. In JSF Version 2, it is not, nor does the JSV2 View template get compiled into Java code like regular JSPs do.


Customer surveys are for companies who didn't pay proper attention to begin with.
Abhilash Sharma
Ranch Hand

Joined: Dec 05, 2010
Posts: 67

Thanks a Alan and Tim for your valuable suggestions. I think firstly,I need to built my app with JSP and Servlets and then transform it to JSF.(just to learn how things work with jsf)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Abhilash Sharma wrote:Thanks a Alan and Tim for your valuable suggestions. I think firstly,I need to built my app with JSP and Servlets and then transform it to JSF.(just to learn how things work with jsf)


That may not be as effective as you hope. JSF has a very different approach to webapps than servlets and JSPs do.
Abhilash Sharma
Ranch Hand

Joined: Dec 05, 2010
Posts: 67

So what you are saying is that I should concentrate on JSP AND SERVLETS and leave JSF. I am a fresher and will applying for jobs soon. So, I thought may be I should learn JSF (may be JSP+SERVLETS AND JSF LOOKS GOOD ON RESUME).
Couple of days back,I bought this CORE JAVASERVER FACES book ,start learning and found the difference between the approaches.(like form data directly send to bean wheras in other case it would sent to servlet/jsp).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

When applying for jobs, the best strategy is to see what employers in your area are demanding and concentrate on that. Not so long ago, around here that would have been Struts.

Technically, form data isn't "sent directly" to a bean. It's sent to the FacesServlet, which acts as the Master Controller. JSF handles getting the data to/from beans.

If I were hiring, more important that specific frameworks to me would be how well you understand basic HTTP and Model/View/Controller. A lot of people don't understand HTTP very well at all. If you have a good understanding of those two concepts and how they work, then the more specific frameworks such as JSP/Servlet, Struts, JSF, Tapestry, and so forth will make a lot more sense to you.
Abhilash Sharma
Ranch Hand

Joined: Dec 05, 2010
Posts: 67

Thanks Tim
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

Sorry for insolent question, but...
Once I was preparing for interview where I was like from neighboring planet.
I didn't know what was HTTP( luckily they didn't ask me) and how data is sent over the Internet (question from another interview).
I understand that user submits data. How does data go through network and what it has to do with HTTP protocol?
At Apply request values phase user's data is assigned to variable 'submittedValue' of corresponding UIComponent. Why is String assigned to submittedValue and
only after that conversion is applied?
My interviewers asked similarly as Tim would ask.
At one interview I was told that I needed a good study at first, at another they recommended me to move to Struts and Tapestry. I told that JSF is better but I could not explain why. I hope jsf is better.

Sorry for shameless questions but it is the only place for me to ask.


True person is moral, false is right!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integerate JSF,servlet and JSP