7

My server is glassfish v3, my browser is firefox 3.6.3 and i am using Netbeans 6.8 My question is why the textfield is not showing up in my browser. I only see the label.

<?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core">
            <h:head>
                <title>Lookup</title>
            </h:head>
            <h:body>
                <fieldset>
                <legend>Enter Your Customer ID</legend>
                <p>Legal ids are id001, id002, and id003.</p>
                <f:view>
                <h:form>
                    Customer ID:
                    <h:inputText value="#{bankForm.customerId}" />
                    <h:commandButton value="Show Current Balance"
                                     action="#{bankForm.findBalance}" />
                </h:form>
                </f:view>
                </fieldset>
            </h:body>
    </html>

The 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>*.jsf</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>pages/customer-lookup</welcome-file>
    </welcome-file-list>
</web-app>
AnAmuser
  • 1,885
  • 5
  • 26
  • 42

4 Answers4

15

You need to make sure that the request URL (as you enter in browser address bar) matches the url-pattern of the FacesServlet. I.e. do not open the page by http://example.com/context/page.xhtml, but open it by http://example.com/context/page.jsf. Otherwise the FacesServlet will not be invoked and your XHTML page with JSF components will not be parsed in any way. You'll only see "plain HTML" tags like <fieldset> and so on in the browser and you will see the JSF source code unchanged in the returned HTML source when you do a View Source in browser.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Ok. Now I have changed the welcome file be a jsf file, and it works. As you probably can guess I am a total newbie on this web thing. I am trying to do some tutorials, but it is frustrating when even these easy things won't work:) – AnAmuser Jun 09 '10 at 11:36
  • 2
    It's a matter of reading the right tutorials the right way. I suggest you to kickoff here: http://www.coreservlets.com/JSF-Tutorial/jsf2/ – BalusC Jun 09 '10 at 11:42
  • 1
    AnAmuser, if you feel this answer is correct, in that it resolved your problem, click the checkbox next to the answer to "accept" it – Brian Leathem Jun 10 '10 at 02:43
8

Add this to your web.xml :

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
Amira Manai
  • 2,599
  • 8
  • 40
  • 60
2

The problem you faced with may be solved in web.xml file stored in the WEB-INF dir in your web application project. You need to open that file and add the following xml content in order to make your pages running properly.

 <web-app>
    ...
    ...
    ...
    <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
  </web-app>

If your .xml file doesnt exist in the mentioned dir, you can add it by clicking on your web application project, add new file and then choose Standard Deployment Descriptor (web.xml)

miksiii
  • 2,426
  • 26
  • 22
0

Check if you have configured Faces-Servlet on this page

Dejell
  • 13,947
  • 40
  • 146
  • 229
  • Mapping the Faces Servlet is automatically done for you when using a Java EE 6server such as Sun GlassFishTM Enterprise Server v3. – AnAmuser Jun 09 '10 at 09:08
  • 1
    ok. but what it the post fix of the page? .xhtml? do you URL it as somthing.jsf and set in WEB.xml to map the servlet on *.jsf? – Dejell Jun 09 '10 at 09:23
  • It is a xhtml file. and the web.xml file is now in the question – AnAmuser Jun 09 '10 at 10:37