Hi everyone! I am working with JSF and servlets. I need to make a servlet that uses JSF tags to generate a web page. I cannot do it using JSP. But the instruction out.println() does not work with JSF tags. I want to do something like:
PrintWriter out = response.getWriter(); out.println( "<hutputText value=\"Some Text\" />" );
But it does not work. The resulting page does not shows anything. I think it is because the resulting page must be only HTML. How can I work with JSF inside the servlet? Is there a way I can work with faces components and then get their resulting HTML code as a String to put it in the out.println()?
What you want is, ehm, strange. And it's impossible too. In fact a JSF page will generate a Servlet when it's processed on the server side. What you found out is right: a servlet can only generate HTML that is send to the client (the browser) immediately, without further processing.
I suggest that you may be better off when you first read some more about Servlets, JSPs and JSF. Perhaps the chapter "The web tier" from the Sun Java EE 5 Tutorial is a good starting point.
There already is a servlet that uses JSF tags to generate a web page. It's the JSF Servlet.
JSF isn't just a set of taglibraries, it's an entire infrastructure. Before you break the rules, you need to know how they work.
What it looks like you actually really intended to do was dynamically generate JSF page source and then apply it. That's not something I'd do lightly and I've been working with JSF for over 2 years now.
On the other hand, I've never felt the need to. JSF can do an awful lot in a fairly simple way. So simple, in fact, that one of the biggest problems a lot of people seem to have with it is that they try to build complex solutions for simple problems.
An IDE is no substitute for an Intelligent Developer.