Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF Form is not showing up [duplicate]

Tags:

jsf

jsf-2

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>
like image 906
AnAmuser Avatar asked Jun 08 '10 23:06

AnAmuser


2 Answers

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.

like image 152
BalusC Avatar answered Sep 22 '22 19:09

BalusC


Add this to your web.xml :

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
like image 44
Amira Manai Avatar answered Sep 22 '22 19:09

Amira Manai