JSF表格没有出现

AnA*_*ser 7 jsf jsf-2

我的服务器是glassfish v3,我的浏览器是firefox 3.6.3,我正在使用Netbeans 6.8我的问题是为什么textfield没有显示在我的浏览器中.我只看到标签.

<?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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 14

您需要确保该请求的URL(如你在浏览器地址栏输入)匹配url-patternFacesServlet.即不要通过http://example.com/context/page.xhtml打开页面,而是通过http://example.com/context/page.jsf打开它.否则FacesServlet将不会调用,并且不会以任何方式解析具有JSF组件的XHTML页面.您只能<fieldset>在浏览器中看到"纯HTML"标签等等,当您在浏览器中执行View Source时,您会在返回的HTML源代码中看到JSF源代码未更改.

  • 这是以正确的方式阅读正确的教程的问题.我建议你在这里开球:http://www.coreservlets.com/JSF-Tutorial/jsf2/ (2认同)

Ami*_*nai 8

将其添加到您的web.xml:

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)