This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
JSF is not JSP. There are several things wrong here.
1. You're not using valid XML syntax. In XML, element attributes must be enclosed in double-quotes not single-quotes. And quotes are never optional, the way they are in straight HTML.
2. You're using JSTL. Although JSTL often works, it also often causes problems. There's really nothing in JSTL that JSF can't do better as native JSF.
3. You didn't properly define the JSF View. You're missing the JSF view tags.
I'm not sure if the old JSP format even works in JSF2. I've been using xhtml for the last several years. But in any event, use of the JSP "page", "taglib" and DTD definitions isn't what I'd recommend even if they still work. It's preferable to use XML form, which references XML schemas instead of DTDs.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Dec 25, 2010
Thanks Tim, I just started JSF about a day ago and was curious why this wasn't working. I'm still confused overall on why JSF is used. There are many articles that say the advantages and what not, but the core idea is still vague. Perhaps, you can tell me why you use JSF and what benefits does it give you? I'd gladly appreciate it. Thanks.
JSF makes large-scale webapps easier to code and maintain. It provides a whole raft of useful functions such as automated display/capture of form variables, validation, error reporting and the like and allows separation of duties between page (View) designers and back-end coders. It's a bit heavier than raw JSPs, but because it provides both services and structure, it tends to pay for itself when the going gets rough.
JSF is only one of a number of frameworks created to make J2EE webapp development more productive - for example Struts. JSF's main advantage is that it's a pretty straightforward MVC architecture, and MVC has long been recognized as an effective paradigm for GUIs.
Joined: Dec 25, 2010
Thanks Tim for the previous reply. I had one more question.
Is there a way to incorporate JSF into servlets and jsp. I want to combine all of them.
Usually for my MVC WITHOUT JSF I do...
User clicks register button ----> RegisterUserServlet.java as "GET" -----> RegisterUser.jsp ------> RegisterUserServlet.java as "POST" -----> Update to database....
With what I know of JSF so far, is there a way to do this----->
User clicks register button ----> RegisterUserServlet.java as "GET" -----> RegisterUser.jsp or RegisterUser.xhtml and I use JSF tags/beans here for validation ----> RegisterUserServlet.java as "POST" --->Update to database
In a regular JSP page, I would use <input name='firstname'> to send attributes to the servlet... but in a JSF page, I can't do that.
My question is.... how can I write a form in jsp/xhtml with jsf tags, validate it, and then send the contents of that form to the servlet?
MY OVERALL GOAL WOULD BE: Use the jsp/xhtml for validation with THE JSF then send that validated data to the servlet. I CANNOT DO THE VALIDATION EASILY WITH THE JSP ALONE. I was hoping to use the JSF as the validation.
Instead of Servlet(GET) ---> JSP --->SERVLET(POST)
It would be Servlet(GET) ---->JSF(validate it) ----> SERVLET(POST)
You can use servlets, JSP, and JSF (and Struts!) all in the same application.
However, you cannot feed JSF Views directly to servlets. That's because JSF Views must go to the FacesServlet, which serves as the Controller part of the JSF Model/View/Controller paradigm, just as the backing bean serves as the Model. Likewise, a Servlet/JSP cannot feed directly into a JSF View. One of the things that trips up a lot of people is that in JSF1, the original (pre-facelets) View was a "JSP". However, unlike normal JSPs, the JSF View JSP had to be populated by the FacesServlet in response to a Faces URL request.
JSF isn't like brute-force J2EE JSP/servlet. JSF action processors don't go out and get data. Instead, the controller injects the data into the backing bean - but only if each and every item passes validation. If not, the bean doesn't update and the action processor(s) isn't invoked. JSF manages the error reporting and redisplay of the form automatically under control of the FacesServlet.
JSF pages can contain URL references to JSPs and servlets, but these are references, which get fired as browser-side requests. Likewise, JSPs and servlets can build web pages that contain JSF URL references in them. That all works very well.
What you can't do, however, is mix the two types of technologies in a single request (other than by forwarding). A request/response cycle must either be JSP/servlet or JSF, not a mishmash of both.
Joined: Dec 25, 2010
Nicely put Tim, I guess maybe If I study it for a month or so, then I can see the views more clearly. Thank you for your spending time answering the question. I appreciate it.