views:

94

answers:

2

hi i want to take out the common content in the 2 FACES JSPS and put in one jsp and include two tabs in that FACESJSP and those two tabs will show the differet content any help with sample code pls?

A: 

you probably want to use tiles

nont
+1  A: 

It depends on the view technology in question. In JSP you can use <jsp:include> for this. In Facelets you can use <ui:include> or <ui:composition> for this.

When using JSF on JSP, you need to ensure that every include page has its own <f:subview> with an unique ID.

Basic example:

main.jsp:

<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

<f:view>
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
        <head>
            <title>Main page</title>
        </head>
        <body>
            <jsp:include page="header.jsp" />
            <h2>Content</h2>
            <jsp:include page="footer.jsp" />
        </body>
    </html>
</f:view>

header.jsp

<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:subview id="header">
    <h1>Header</h1>
</f:subview>

footer.jsp

<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:subview id="footer">
    <h3>Footer</h3>
</f:subview>

You can even dynamically include a page, e.g.

<jsp:include page="#{bean.page}" />

where #{bean.page} can return a page relative URL like pagename.jsp.

When using JSF on Facelets (you aren't, but this is just informal), the examples for Facelets can be found in their developer guide. It's far more powerful than JSP and well suited for JSF.

BalusC