Question

Here how look my .jspx files:

<?xml version='1.0' encoding='utf-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core">
     <jsp:output omit-xml-declaration="true"  doctype-root-element="HTML" doctype-system="http://www.w3.org/TR/html5"/>
    <jsp:directive.page contentType="text/html;charset=utf-8"/>
    <f:loadBundle basename="my.pack.resource" var="r"/>
    <f:loadBundle basename="my.pack.error" var="e"/>
    <f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html utf-8"/>
            <meta name="viewport" content="width=device-width"/>
            <title> Some title </title>
            <jsp:directive.include file="/temp/myLayout.jspf" />            
        </head>


        <body>

            <h:form>            

                <h:commandLink .........

                </h:form>

        </body>


        </html>
    </f:view>
</jsp:root>

In order to keep my view files clear and small I would like to put all above and after body in templates and include it in my .ispx files and pass title as parameter.

If anybody knows solution, please help.

EDIT I have changed my view from .jspx to .xhtml, but my servlet filters now don't work. Here my web.xml:

   <?xml version = '1.0' encoding = 'windows-1252'?>
<web-app 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"
         version="2.5">
    <context-param>
        <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
        <param-value>*.xhtml;*.jsf</param-value>
    </context-param>
    <filter>
        <filter-name>loginFilter</filter-name>
        <filter-class>my.pack.filterpack.LoginFilter</filter-class>
    </filter>
    <filter>
        <filter-name>remebermefilter</filter-name>
        <filter-class>my.pack.filterpack.RemeberMeFilter</filter-class>
    </filter>
    <filter>
        <filter-name>NoCacheFilter</filter-name>
        <filter-class>my.pack.filterpack.NoCacheFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>loginFilter</filter-name>
        <url-pattern>/view/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>remebermefilter</filter-name>
        <url-pattern>/login/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>NoCacheFilter</filter-name>
        <url-pattern>*.xhtml</url-pattern>                
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>


    <!-- servlet mappings -->

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


    <error-page>
        <error-code>500</error-code>
        <location>/index.jsp</location>
    </error-page>
    <error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/viewExp.jsp</location>
    </error-page>
    <listener>
        <listener-class>my.pack.timer.MyJobManager</listener-class>
    </listener>
</web-app>
Was it helpful?

Solution

This is one of the reasons why JSP(X) is abandoned, deprecated and succeeded by Facelets 4 years ago. JSP(X) doesn't offer easy templating capabilities in order to achieve this kind of requirements.

Just migrate to Facelets. Rename .jspx to .xhtml and replace <jsp:xxx> tags by <ui:xxx> tags. Your functional requirement is answered in 2nd example of How to include another XHTML in XHTML using JSF 2.0 Facelets?

Facelets is natively available in JSF 2.x. If you're still using JSF 1.x, then you can just install it separately as per its documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top