I am using eclipse juno and I am trying to build a website. I am building the User interface and I would like to use JSF. The following code runs and when I run the file the information is displayed correctly on the screen.
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="Stylesheets/flashcard.css" />
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<h:commandButton value="Click"></h:commandButton>
</h:form>
</f:view>
However I have read that it is better practice to write the code like this. This code just displays a blank page.
<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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="Stylesheets/flashcard.css" />
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<h:commandButton value="Click"></h:commandButton>
</h:form>
</f:view>
</body>
</html>
The difference is subtle but in the second file I don’t use jsp <%@ tags if this makes sense. When creating the second file I chose JSF xhtml or something. Does anybody know what the problem might be?
Just rename the extension of the physical view file from
some.jsptosome.xhtml. You don’t need to change the extension in the URL which you originally used. If you opened it by/some.jsf, then you should keep opening it by/some.jsf.Note that I assume that you’re using JSF2 and not the legacy JSF 1.x. Facelets is namely not natively supported by JSF 1.x. Also note that Facelets is not “just a better practice”, you must use it in JSF2 as JSP is deprecated.
See also: