0

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>
ella2964823
  • 107
  • 1
  • 9

1 Answers1

1

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • BalusC thank you for help.I have changed my view files to .xhtml, but now my servlet filters don't work. Can you help? – ella2964823 Dec 11 '13 at 07:18
  • Alter their mappings accordingly. – BalusC Dec 11 '13 at 08:43
  • Get rid of all `FORWARD` entries. It defaults to the right one, `REQUEST` already. On contrary to JSP(X), Facelets doesn't use the old fashioned dispatcher anymore to locate the view. – BalusC Dec 11 '13 at 09:26
  • Thanks balusC, it helped me, but now in my RemeberMeFilter FacesContext.getCurrentInstance() is null. – ella2964823 Dec 11 '13 at 10:02
  • That's a different problem. You're not supposed to use JSF artifacts in servlet filters anyway. For example, if you intend to use `FacesContext` to grab a session scoped managed bean, just get it from the `HttpSession` directly. – BalusC Dec 11 '13 at 10:05