1

I'm having an issue with converting a project from what I think is jsf 1.1 or 1.2, to jsf 2.0 using facelets.

I've read many Q's on SO about how to do this and I'm still having issues. The problem i'm having is that the jsf tags are not being rendered as html tags.

I'm newer to JSF and still trying to get the hang of it.

Main Page:

<?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"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:t="http://myfaces.apache.org/tomahawk" 
        xmlns:p="http://primefaces.prime.com.tr/ui"
        xmlns:rich="http://richfaces.org/rich"
        xmlns:j4j="http://javascript4jsf.dev.java.net/">

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Language" content="en-us">
    <link type="text/css" rel="stylesheet" href="../theme/style.css" />

    <title>Administration</title>

</h:head>

<h:body>

<div id="home"><ui:include page="../common/includes/page.html" flush="true" /></div>


    <f:loadBundle basename="path/to/messages" var="cca" />
    <div class="title">
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td colspan="2">
            <h1>Administration</h1>
            </td>
        </tr>
    </table>
    </div>
    <h:form style="display: inline;">

        <t:div styleClass="header_section">Main</t:div>

        <div class="left clearL contentBox">
            <ul>
                <li>
                    <h:commandLink id="personnel" action="go_personnel">
                        <h:outputText value="Membership Management" styleClass="portallink" />
                    </h:commandLink>
                </li>

                <li>
                    <h:commandLink id="funding" action="go_fund">
                        <h:outputText value="Funding Source Management" styleClass="portallink" />
                    </h:commandLink>
                </li>

                <li>
                    <h:outputLink value="#">
                        <h:outputText value="Publications and Bibliographies" styleClass="portallink"/>
                    </h:outputLink>
                </li>
            </ul>
        </div>

        <t:div styleClass="header_section">Pages</t:div>

        <div class="left clearL contentBox">

            <ul>
                <li>
                    <h:commandLink id="mbr" action="go_membership">
                        <h:outputText value="Membership" styleClass="portallink"/>
                    </h:commandLink>
                </li>
            </ul>

        </div>

        <t:div styleClass="header_section">Status</t:div>

        <table width="425px">
            <tr>
                <td width="90%">

                </td>       
            </tr>
        </table>

    </h:form>

    <div class="footer">

    <div class="left">
        <p class="left footerText">Contact <a href="#">Systems Management Services</a></p>
        <p class="left clearL">Version 1.8.0</p>
    </div>

    <div class="right">
        <p class="footerText right"><a href="#banner">Top of Page</a></p>
    </div>

</div>
</h:body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">


    <context-param>
        <description>
            State saving method: "client" or "server" (= default) See
            JSF Specification 2.5.3
        </description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default). Defines the amount (default = 20) of the latest
            views are stored in session.
        </description>
        <param-name>
            org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
        </param-name>
        <param-value>20</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default). If true (default) the state will be serialized to
            a byte stream before it is written to the session. If false
            the state will not be serialized to a byte stream.
        </description>
        <param-name>
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION
        </param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            Only applicable if state saving method is "server" (=
            default) and if
            org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (=
            default) If true (default) the serialized state will be
            compressed before it is written to the session. If false the
            state will not be compressed.
        </description>
        <param-name>
            org.apache.myfaces.COMPRESS_STATE_IN_SESSION
        </param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            This parameter tells MyFaces if javascript code should be
            allowed in the rendered HTML output. If javascript is
            allowed, command_link anchors will have javascript code that
            submits the corresponding form. If javascript is not
            allowed, the state saving info and nested parameters will be
            added as url parameters. Default: "true"
        </description>
        <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <description>
            If true, rendered HTML code will be formatted, so that it is
            "human readable". i.e. additional line separators and
            whitespace will be written, that do not influence the HTML
            code. Default: "true"
        </description>
        <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            If true, a javascript function will be rendered that is able
            to restore the former vertical scroll on every request.
            Convenient feature if you have pages with long lists and you
            do not want the browser page to always jump to the top if
            you trigger a link or button action that stays on the same
            page. Default: "false"
        </description>
        <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Used for encrypting view state. Only relevant for client
            side state saving. See MyFaces wiki/web site documentation
            for instructions on how to configure an application for
            diffenent encryption strengths.
        </description>
        <param-name>org.apache.myfaces.SECRET</param-name>
        <param-value>NzY1NDMyMTA=</param-value>
    </context-param>

    <context-param>
        <description>
            Validate managed beans, navigation rules and ensure that
            forms are not nested.
        </description>
        <param-name>org.apache.myfaces.VALIDATE</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
            A class implementing the
            org.apache.myfaces.shared.renderkit.html.util.AddResource
            interface. It is responsible to place scripts and css on the
            right position in your HTML document. Default:
            "org.apache.myfaces.shared.renderkit.html.util.DefaultAddResource"
            Follow the description on the MyFaces-Wiki-Performance page
            to enable StreamingAddResource instead of DefaultAddResource
            if you want to gain performance.
        </description>
        <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
        <param-value>
            org.apache.myfaces.renderkit.html.util.DefaultAddResource
        </param-value>
        <!--param-value>org.apache.myfaces.component.html.util.StreamingAddResource</param-value-->
    </context-param>

    <context-param>
        <description>
            A very common problem in configuring
            MyFaces-web-applications is that the Extensions-Filter is
            not configured at all or improperly configured. This
            parameter will check for a properly configured
            Extensions-Filter if it is needed by the web-app. In most
            cases this check will work just fine, there might be cases
            where an internal forward will bypass the Extensions-Filter
            and the check will not work. If this is the case, you can
            disable the check by setting this parameter to false.
        </description>
        <param-name>
            org.apache.myfaces.CHECK_EXTENSIONS_FILTER
        </param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>blueSky</param-value>
    </context-param>
    <context-param>
        <description>
        Comma-delimited list of context-relative resource paths under which the JSF implementation
will look for application configuration resources, before loading a configuration resource
named /WEB-INF/facesconfig.xml (if such a resource exists).</description>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>
    <context-param>
        <description>
        The default suffix for extension-mapped resources that contain JSF components.
Default is '.jsp'.</description>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jsp</param-value>
    </context-param>
    <context-param>
        <description>
        Monitors Faces JSP files for modifications and synchronizes a running server with
the changes without restarting the server. If this parameter is set to false or
removed from the deployment descriptor, any changes made to Faces JSP files may
not be seen by the server until it is restarted. This parameter is usually set
to true while the Faces JSP files are being developed and debugged in order to
improve the performance of the development environment.</description>
        <param-name>com.ibm.ws.jsf.JSP_UPDATE_CHECK</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <description>
        Load JSF runtime when the application server starts up. If this parameter is set to false or removed,
JSF runtime will be loaded and initialized when the first JSF request is processed.
This may disable custom JSF extensions, such as factories defined in the project.</description>
        <param-name>com.ibm.ws.jsf.LOAD_FACES_CONFIG_AT_STARTUP</param-name>
        <param-value>true</param-value>
    </context-param>
    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>


    <filter>
        <filter-name>extensionsFilter</filter-name>
        <filter-class>
            org.apache.myfaces.webapp.filter.ExtensionsFilter
        </filter-class>
        <init-param>
            <description>
                Set the size limit for uploaded files. Format: 10 - 10
                bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
            </description>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
        </init-param>
        <init-param>
            <description>
                Set the threshold size - files below this limit are
                stored in memory, files above this limit are stored on
                disk.

                Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
            </description>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>

    <listener>
     <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
 </listener>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <display-name>
        Apache-Axis Servlet</display-name>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>
        org.apache.axis.transport.http.AxisServlet</servlet-class>
    </servlet>
    <servlet>
        <display-name>
        Axis Admin Servlet</display-name>
        <servlet-name>AdminServlet</servlet-name>
        <servlet-class>
        org.apache.axis.transport.http.AdminServlet</servlet-class>
        <load-on-startup>100</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/servlet/AxisServlet</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>*.jws</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AdminServlet</servlet-name>
        <url-pattern>/servlet/AdminServlet</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
        <welcome-file>/index.html</welcome-file>
    </welcome-file-list>

</web-app>

faces-config.xml

<?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_2_0.xsd"
    version="2.0">


    ..managed beans removed..

    ..nav rules removed..

</faces-config>
Catfish
  • 17,019
  • 47
  • 183
  • 323
  • Might be this ` – Bhesh Gurung Oct 20 '11 at 15:13
  • Another reason could be that the __Faces Servlet__ is not invoked. – Bhesh Gurung Oct 20 '11 at 15:20
  • You do not do it yourself but if the request __url-pattern__ is right then it should be invoked. – Bhesh Gurung Oct 20 '11 at 15:25
  • 1
    The sentence "The problem i'm **not** having is that the jsf tags are **not** being rendered as html tags." is full of contradictions. It boils down to that JSF tags are properly been rendered as HTML tags. Or do you actually mean the inverse? Another issue is that you've declared in `web.xml` to stick to old JSP as default view technology, but yet you're using Facelets tags in the view. What view technology are you really using (you didn't mention its filename/extension) and what one do you want to use? – BalusC Oct 20 '11 at 15:25
  • Sorry, I've edited the question. Basically the jsf tags are not rendering as html tags. I'm trying to use facelets. Where do I need to change this in web.xml? – Catfish Oct 20 '11 at 15:34

1 Answers1

2

So, you want to use JSF 2.0 on Facelets? I gather that you also want to be able to still use the old JSP files?

It's hard crawling through that web.xml monster in your question with a mix of JSF 1.x and JSF 2.x declarations. The key points are the removal of the javax.faces.DEFAULT_SUFFIX (which you've incorrectly set to .jsp) and changing the FacesServlet mapping on *.xhtml.

<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>*.xhtml</url-pattern>
</servlet-mapping>

Also, your ExtensionsFilter can better be mapped on a single servlet mapping of FacesServlet.

<filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

This way the Facelets files must work properly. When a foo.xhtml does not exist, but a foo.jsp does exist, then it will be served instead behind *.xhtml URL pattern.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • I've changed my web.xml file as you've suggested and i'm getting this error `Unable to find class 'com.sun.facelets.FaceletViewHandler'`. – Catfish Oct 20 '11 at 16:21
  • Remove that line and all other JSF 1.x related Facelets declarations from `faces-config.xml`. See also the "See also" link for more detail. – BalusC Oct 20 '11 at 16:32
  • That error was caused because I needed to download the facelets-lib.jar file. – Catfish Oct 20 '11 at 18:20
  • You shouldn't need that. It's already included in JSF 2.0 JAR file. Have you read the "See also" link? Keeping it would only result in future troubles. Perhaps you were reading a guide how to install Facelets 1.x for JSF 1.x instead of a fullworthy JSF 2.x tutorial. – BalusC Oct 20 '11 at 18:23
  • Yes I read your see also for the past few days. I don't know if I even haev the JSF 2.0 jar. How can I tell? – Catfish Oct 20 '11 at 18:34
  • Depends on the servletcontainer and JSF implementation used. But if new JSF 2.0 features/tags like Facelets 2.0 and ``, etc works, then you've JSF 2.0. – BalusC Oct 20 '11 at 18:38