1

I have the following HTML file:

<?xml version="1.0" encoding="UTF-8"?>
<!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"
>

<head>
<title>First Example JSF Program</title>
<head>

<body>
   Hello <h:outputText value="Darwin"></h:outputText>!
</body>
</html>

But the output, expected 'Hello Darwin!' won't appear. Only 'Hello !' appears. Why is this? There are no errors and I'm sure it has all JAR files necessary - if it didn't it would throw an error right?

Cheers

P.S. This is an HTML 5 file, does that make a difference?

Katana24
  • 8,706
  • 19
  • 76
  • 118

1 Answers1

2

That can happen if the request URL as you see in browser's address did not match the <url-pattern> of the FacesServlet as definied in webapp's web.xml and hence the FacesServlet wasn't able to do its job of performing all the JSF works.

If you right click the page in browser and do View Source, you should have noticed that the JSF <h:outputText> tag is completely unprocessed. JSF tags aren't recognized by the webbrowser. They are supposed to be processed by the FacesServlet in the webserver. They are supposed to generate proper HTML code and the final HTML result should not contain any JSF tags at all.

You need to make sure that the request URL as you see in browser's address matches the <url-pattern> of the FacesServlet as definied in webapp's web.xml. Imagine that it is *.jsf like as

<url-pattern>*.jsf</url-pattern>

then you should need to change the URL in the address bar from /some.xhtml to /some.jsf.

Alternatively, you could also just change the web.xml to map the FacesServlet on *.xhtml directly

<url-pattern>*.xhtml</url-pattern>

so that you don't need to fiddle with virtual URLs anymore.

As to the file having HTML5 doctype, no that makes absolutely no difference. I'd only remove that XML prolog as that's valid for XHTML doctype only. See also Is it possible to use JSF+Facelets with HTML 4/5?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thats understandable - I fixed the web.xml file but now Im getting an HTTP:404 error – Katana24 Nov 22 '12 at 15:40
  • 1
    @Katana24 check the url that you used to access your page, it could be that you used `/faces/yourpage.xhtml` and now you only need to use `/yourpage.xhtml`. – Luiggi Mendoza Nov 23 '12 at 07:41