0

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>
Tiny
  • 27,221
  • 105
  • 339
  • 599
Berry
  • 128
  • 1
  • 15
  • Explain 'not visible' from a developer point of view. Did you checked how it looks like in the source of the browser developer tool? – Kukeltje Sep 09 '15 at 15:49
  • By 'not visible' I mean that when I run the project I can see everything except everything between ``. If I then inspect the elements of the page it is present in the list, but says it's 0px x 0px. – Berry Sep 09 '15 at 16:10
  • This: http://s2.postimg.org/wcdx018u1/2015_09_09_18_09_20.jpg – Berry Sep 09 '15 at 16:11
  • It's a true XHTML file. This is my doctype: ` ` – Berry Sep 09 '15 at 16:23
  • When you inspect `` do you see `` tag or `
    `? If you see `` then you have wrong mapping in `web.xml`.
    – Geinmachi Sep 09 '15 at 16:52
  • I see `` and I've just added my `web.xml` to the original message. – Berry Sep 09 '15 at 17:16
  • 1
    Check which one of the search results contains your solution. https://www.google.nl/search?q=jsf+tags+not+rendered+stackoverflow – Kukeltje Sep 09 '15 at 17:26

1 Answers1

2

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.)

syntaxerror
  • 106
  • 1
  • 6
  • 1
    It is better to add: Faces Servlet *.xhtml And remove faces/index.xhtml as said in [this answer](http://stackoverflow.com/questions/3112946/jsf-returns-blank-unparsed-page-with-plain-raw-xhtml-xml-el-source-instead-of-re). – Javier Haro Sep 09 '15 at 18:10