I'm trying to follow this tutorial on jsf: https://netbeans.org/kb/docs/web/jsf20-intro.html
In the "Wiring Managed Beans to Pages" chapter you have to switch the HTML form element for an equivalent JSF HTML form component. But after I do so (simply commenting/uncommenting already present code) it isn't visible.
I've added xmlns:h="http://xmlns.jcp.org/jsf/html"
to the html tag; I get no errors from the IDE; the form shows up in inspect element; I've also tried xmlns:h="http://java.sun.com/jsf/html"
instead, but still nothing.
Here's my page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
<!--<h:outputStylesheet name="css/stylesheet.css" />-->
<title>Greeting</title>
</head>
<body>
<div id="mainContainer">
<div id="left" class="subContainer greyBox">
<h4>Hi, my name is Duke!</h4>
<h5>I'm thinking of a number
<br/>
between
<span class="highlight">0</span> and
<span class="highlight">10</span>.</h5>
<h5>Can you guess it?</h5>
<!-- <form action="response.xhtml">
<input type="text" size="2" maxlength="2" />
<input type="submit" value="submit" />
</form>-->
<h:form>
<h:inputText id="userNumber"
size="2"
maxlength="2"
value="#{UserNumberBean.userNumber}"/>
<h:commandButton id="submit" value="submit" action="response"/>
</h:form>
</div>
<div id="right" class="subContainer">
<img src="duke.png" alt="Duke waving" />
<!--<h:graphicImage url="/duke.png" alt="Duke waving" />-->
</div>
</div>
</body>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
JSF-Tags like <h:form>
and <h:inputText>
being returned to the client (your browser) instead of being rendered as proper HTML are a sure sign that your whole setup is wrong. (A browser will duly ignore any tags that it doesn't understand, that's why you don't get to see any of the contents of the form.)
If you are mapping your URL pattern like so:
<url-pattern>/faces/*</url-pattern>
you should then remove the second welcome file entry
<welcome-file>index.xhtml</welcome-file>
because this can never work, because it does NOT match against the pattern, so the whole request is NOT processed by FacesServlet
in which case the plain .xhtml file is served as-is!
(It even says so explicitly in the tutorial you are referring to, at the end of the "Adding JSF 2.x Support to a Web Application" section.)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments