views:

773

answers:

7

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"&gt;
    <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"&gt;
    <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"&gt;

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

A: 

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

Maxime ARNSTAMM
What should I check there? I'm a newbie to jsf and j2ee and I've every thing the tutorial says regarding the web.xml and the faces-config.xml. That is: set the welcome page in the web.xml, set the resourse bundle for localization purposes in the faces-config.xml and set some pageflow properties in the faces-config.xml.
Toto
Show us those two files, that'll help.
Maxime ARNSTAMM
OK, I've edited the question.
Toto
@Eligriv: that's not needed in JSF 2.0 as Facelets is the default view handler.
BalusC
ah, see, i'm short of ideas then :p sorry
Maxime ARNSTAMM
+2  A: 

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"&gt;
BalusC
Thanks. I checked it and the url pattern was wrong. I've change it to /firstcup/*. However, the url I'm entering is http://localhost:8081/firstcup/ after restarting the server and re-deploying the application, but but I keep getting the un-rendered jsf code. What else could it be?
Toto
Sorry, the url i'm entering in the browser is localhost:8081/firstcup with a slash (/) at the end (I don't know why that last slash is not being shown in the comment)
Toto
That slash doesn't matter. Maybe the `FacesServlet` failed to start for some reason. Read the server startup logs to know more.
BalusC
Yes, I included the xmlns attributes (I've updated the question).
Toto
Nothing about FacesServlet in glassfish logs.
Toto
+1  A: 

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>
Toto
Odd. You told that you've tried `http://localhost:8081/firstcup/greetings.xhtml` as well. That should have worked as well without a welcome file. At least, the root cause of the problem is still that the request was **not** been passed through the `FacesServlet`.
BalusC
A: 

I just got the same problem, with JSF2 in JBoss 4.2.3 My war module is inside an ear which also hosts the JSF2 jar. I found that JBoss has its own JSF jar, which is 1.2 version and do not come with facelet. That's why my jsf tags not rendered (probably yours, too). I am looking for ways to find out how I can put JSF2 in my app without removing that of JBoss. Any ideas?

Hillman
Sorry Hillman, I've solved my problem editing the welcome-file inside web.xml. So, I think we have different problems. I suggest you create a new question with your problem, linking it to this one to state that is a similar problem - and avoid being tell that it is the same question, :)
Toto
A: 

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

Mark
A: 

I have the same problem:

<!-- Faces Servlet Mapping -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- welcome file mapping -->
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

This works for index.xhtml, but if I click on login.xhtml, I get the unrendered JSF tags.

Mark
If you want answers, ask a question. Press `Ask Question` button on the top. Don't post questions as answers using `Post Your Answer` ;)
BalusC
A: 

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 stackoverflew

phil-st