开发者

JSF tags not being rendered as HTML [duplicate]

This question already has an answer here: JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output (1 answer) Closed 6 years ago.

I'm following the Java EE firstcup tutorial using Netbeans and Glassfish.

When I execute the JSF web tier I've been instructed to code, the browser gets the same JSF markup coded in the .xhtml file, and the tags are not rendered as HTML tags. I know this by using the view source code in my browser.

For example, for this code:

<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>

The browser should get something like:

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

Right?

Well, my browser is getting jsf code (the first piece of code above) and not the html code (the second piece of code above).

It seems to be a configuration problem in netbeans or glassfish but don't know what. Any ideas?


This is my web.xml file:

<?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>

This is my faces-config.xml file:

<?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>

Moreover:

  • The url I'm entering in the browser is http://localhost:8081/firstcup/ but I've also tried: http://localhost:8081/firstcup/greetings.xhtml
  • I've checked Glassfish logs and there's no information about not being able to load FacesServlet


If JSF tags are not been parsed, then it simply means that the request has not been passed through the FacesServlet. That servlet is the one responsible for all that JSF stuff. You need to verify if the request URL used matches the url-pattern of the FacesServlet. Note that it is case sensitive.

This may however also happen if you opened the file directly in the builtin browser of the IDE. You shouldn't do that. You need to specify the right URL yourself in the address bar of either the builtin browser or an external browser (e.g. MSIE/Firefox).

Update: one more thing, did you declare the JSF HTML taglib in <html xmlns> attribtue? You omitted that in your code snippet.

It should look like

<html 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html">


The following code in web.xml

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

instead of faces/* has solved my problem of non-rendered jsf tags.

Note: *.html causes stackoverflow


Check either your web.xml or your faces-config.xml. Something's obviously missing.

edit : i don't know jsf 2, but in my jsf 1 faces-config.xml i have this :

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

Maybe you should take a look a this. (could be a hint, sorry i cannot help any further)

edit 2 : this is not the answer, sorry


SOLVED: Changing the welcome-file in web.xml to the following solved the problem:

<welcome-file-list>
    <welcome-file>firstcup/greetings.xhtml</welcome-file>
</welcome-file-list>


This may not be relevant to you, but after hours of searching for the solution for a similar problem, my culprit turns out to be this file in 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"/>

For some strange reason JBoss Tools 3.3.0.M2 put that file in my JSF 2.0 project and BOOM! Nothing works. The file looks very innocent yet (probably due to version="1.2") it made me quite frustrated.

I've searched logs (nothing!), WEB-INF/lib, classpaths, even removing dependencies and it turned out to be a single faces-config.xml :-P

Hopefully this helps someone...


I have also suffered from problem of jsf tags, not rendered at all. I used welcome file in web.xml as login/entry.xhtml.

When I changed that file to faces/login/entry.xhtml, it is working well.

It must be due to facesServelet is not intercepting the page. It leads to rendering of only plain html and jsf tags are simply ignored.


Thanks @hendy-irawan

I solved my issue by changed my faces-config header

From

<?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>

To

<?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>


I had the same problem. I deleted some richfaces jars from the WEB-INF/lib and JSF is working now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜