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?
That can happen if the request URL as you see in browser’s address did not match the
<url-pattern>of theFacesServletas definied in webapp’sweb.xmland hence theFacesServletwasn’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 theFacesServletin 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 theFacesServletas definied in webapp’sweb.xml. Imagine that it is*.jsflike asthen 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.xmlto map theFacesServleton*.xhtmldirectlyso 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?