1

I'm trying to include a chunk of static html in all of my pages. I tried the code below and it didn't work. I've also tried a few other ways and can't get it to work. I was reading about somehow using ui tags, but I couldn't get that to work either. What do I need to do to include a page with JSF.

<?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:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">

<h:head>
...
</h:head>
<h:body>

    <jsp:include src="/common/includes/founcred1.html" />
...
</h:body>
Catfish
  • 18,876
  • 54
  • 209
  • 353
  • 1) In which way didn't it work? 2) Which templating engine do you use (facelets or jsp)? – Roman Aug 11 '11 at 15:39
  • It doesn't work in the way posted, plus I tried doing it the JSP way with `<%@ @>`. As far as the templating engine, how would I check that? I have to modify an existing project and i'm new to JSF. – Catfish Aug 11 '11 at 15:41
  • @Roman: XML style already hints that OP is using Facelets. – BalusC Aug 11 '11 at 15:57

2 Answers2

1

Given the XML syntax of your markup, you seem to be using Facelets (*.xhtml) as view technology. Facelets is a completely distinct view technology and the successor of JSP. You should not be using JSP tags in Facelets. Forget JSP for now. Use Facelets tags. They are to be declared by the XML namespage xmlns:ui="http://java.sun.com/jsf/facelets". To include page fragments in Facelets, use <ui:include> tag.

<?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:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">
    <h:head>
        ...
    </h:head>
    <h:body>
        <ui:include src="/common/includes/founcred1.xhtml" />
    </h:body>
</html>

You only need to rename your founcred1.html to founcred1.xhtml and wrap the content in an <ui:composition>.

<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <p>HTML here</p>
</ui:composition>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0
  • You have not declared the jsp namespace.: xmlns:jsp="http://java.sun.com/JSP/Page"
  • I've include pages like this: <jsp:directive.include file="xxx.jspx"/>
  • The included page should be a valid xml file as well.
Thor
  • 6,607
  • 13
  • 62
  • 96
  • When I do it this way, if i look in firebug it is outputting `` rather than the contents of this file. – Catfish Aug 11 '11 at 15:46