代码之家  ›  专栏  ›  技术社区  ›  mmutilva

JSF标记未呈现为HTML[重复]

  •  14
  • mmutilva  · 技术社区  · 16 年前

    我在跟踪 JAVA EE第一杯 教程使用 网豆 玻璃鱼 .

    当我执行已经指示我编码的JSF Web层时,浏览器会得到在.xhtml文件中编码的相同JSF标记,并且这些标记不会呈现为HTML标记。我通过使用 查看源代码 在我的浏览器中。

    例如,对于此代码:

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>Page title here</title>
        </h:head>
        <h:body>
            <h2>
                <h:outputText value="#{bundle.WelcomeMessage}" />
            </h2>
        </h:body>
    </html>
    

    浏览器应该得到如下内容:

    <html ...>
        <head>
            <title>Page title here</title>
        </head>
        <body>
            <h2>
                the welcome message goes here
            </h2>
        </body>
    </html>
    

    对吗?

    好吧,我的浏览器正在获取JSF代码(上面的第一段代码),而不是HTML代码(上面的第二段代码)。

    这似乎是Netbeans或Glassfish的配置问题,但不知道是什么。有什么想法吗?


    这是我的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>/firstcup/*</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>greetings.xhtml</welcome-file>
        </welcome-file-list>
    </web-app>
    

    这是我的faces-config.xml文件:

    <?xml version='1.0' encoding='UTF-8'?>
    
    <!-- =========== FULL CONFIGURATION FILE ================================== -->
    
    <faces-config version="2.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-facesconfig_2_0.xsd">
    
        <application>
            <resource-bundle>
                <base-name>firstcup.web.WebMessages</base-name>
                <var>bundle</var>
            </resource-bundle>
            <locale-config>
                <default-locale>en</default-locale>
                <supported-locale>es</supported-locale>
            </locale-config>
        </application>
        <navigation-rule>
            <from-view-id>/greetings.xhtml</from-view-id>
            <navigation-case>
                <from-outcome>success</from-outcome>
                <to-view-id>/response.xhtml</to-view-id>
            </navigation-case>
        </navigation-rule>
    </faces-config>
    

    此外:

    8 回复  |  直到 10 年前
        1
  •  20
  •   BalusC    16 年前

    如果没有解析JSF标记,那么它仅仅意味着请求没有通过 FacesServlet . 这个servlet负责所有的JSF工作。您需要验证使用的请求URL是否与 url-pattern 面服务 .请注意,它区分大小写。

    但是,如果打开文件,也可能发生这种情况。 直接地 在IDE的内置浏览器中。你不应该那样做。您需要在内置浏览器或外部浏览器(如msie/firefox)的地址栏中自己指定正确的URL。

    更新 :还有一件事,您在 <html xmlns> ATT?您在代码片段中省略了这一点。

    看起来应该像

    <html 
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html">
    
        2
  •  9
  •   LPL user462990    14 年前

    web.xml中的以下代码

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

    而不是 faces/* 已经解决了我的未呈现JSF标记问题。

    注: *.html 导致stackoverflow

        3
  •  0
  •   Maxime ARNSTAMM    16 年前

    检查web.xml或faces-config.xml。显然有东西不见了。

    编辑: 我不知道JSF 2,但在我的JSF 1 faces-config.xml中,我有:

    <application>
       <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    </application>
    

    也许你应该看看这个。(可能是个提示,对不起,我不能再帮你了)

    编辑2:这不是答案,对不起

        4
  •  0
  •   Hendy Irawan    14 年前

    这可能与您无关,但经过数小时寻找类似问题的解决方案后,我的罪魁祸首竟然是WEB-INF/faces-config.xml中的此文件:

    <?xml version="1.0"?>
    <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xi="http://www.w3.org/2001/XInclude"
     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-facesconfig_1_2.xsd"/>
    

    出于某种奇怪的原因,jboss工具3.3.0.m2将该文件放在我的JSF 2.0项目中,然后快速增长!什么都不起作用。这个文件看起来很无辜(可能是由于版本=“1.2”),这让我很沮丧。

    我搜索过日志(什么都没有!),WEB-INF/lib,类路径,甚至删除依赖项,结果是一个单独的faces-config.xml:-p

    希望这能帮助别人…

        5
  •  0
  •   Stephan    13 年前

    我也遇到了 jsf tags ,完全没有渲染。我用欢迎文件 web.xml 作为 login/entry.xhtml .

    当我把文件改为 faces/login/entry.xhtml ,它工作得很好。

    一定是由于 facesServelet not intercepting 页面。 它只会导致渲染平面 HTML JSF 标签被忽略。

        6
  •  0
  •   Melkior    10 年前

    谢谢你@hendy irawan

    我通过更改faces配置头解决了我的问题

    <?xml version="1.0" encoding="UTF-8"?>
    
    <faces-config
        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-facesconfig_1_2.xsd"
        version="1.2">
    
    </faces-config>
    

    <?xml version="1.0" encoding="UTF-8"?>
    
    <faces-config
        xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
        version="2.2">
    
    </faces-config>
    
        7
  •  -1
  •   mmutilva    16 年前

    已解决:更改 欢迎文件 在里面 Web.XML 解决了以下问题:

    <welcome-file-list>
        <welcome-file>firstcup/greetings.xhtml</welcome-file>
    </welcome-file-list>
    
        8
  •  -2
  •   Mark    16 年前

    我也有同样的问题。我从WEB-INF/lib中删除了一些richfaces jar,JSF现在正在工作。

    推荐文章