tags:

views:

35

answers:

3

I have this login.xhtml JSF page:

<?xml version="1.0"?>
<jsp:root version="2.0"
  xmlns:jsp="http://java.sun.com/JSP/Page"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"&gt;
<jsp:directive.page contentType="text/html"/>
<f:view>
  <h:inputText value="#{userBean.id}"/>
</f:view>
</jsp:root>

Output HTML contains properly rendered <input> tag, but <jsp:*> are left untouched. Seems that JSF just didn't understand them. Why?

A: 

The JSP tags you use don't generate any HTML.

The contentType directive affects header, not HTML.

ZZ Coder
But why do they stay in my HTML output?
Vincenzo
A: 

You need to activate JSF, a common way is to point the browser to login.jsf or faces/login.xhtml. If you don't then the file is serves unparsed to the browser

Thorbjørn Ravn Andersen
He is seeing JSP tags unparsed, not JSF tags.
BalusC
+3  A: 

Your're using JSF 2.0 and the file has a *.xhtml extension. You're actually using Facelets as view technology, not JSP. Facelets is the successor of JSP. You cannot mix Facelets with JSP tags. Get rid of all <jsp:> tags, they are worthless and ain't ever going to work in a Facelets page. The JSP tags are only parsed when you name the file *.jsp which will be picked up by servletcontainer's builtin JspServlet. But since you're using JSF 2.0 with Facelets, you already have the FacesServlet for the job. Forget JSP :)

Here's how your XHTML file should look like:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"&gt;
    <h:head>
        <title>Title</title>
    </h:head>
    <h:body>
        <h:inputText value="#{userBean.id}"/>
    </h:body>
</html>

Note that you'd like to put that input component in a <h:form>, but I bet that it'll be just a test example.

Also note that <!DOCTYPE html> is perfectly legit here. You don't need the XHTML doctype. Facelets will take care about setting the right text/html content type, UTF-8 character encoding and so on.

See also:

BalusC
Many thanks, very helpful! :)
Vincenzo
You're welcome.
BalusC