문제

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>
도움이 되었습니까?

해결책

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.

다른 팁

Add this to your web.xml :

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

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)

Check if you have configured Faces-Servlet on this page

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top