unable to load template file using spring and tile integration - templates

I am new to Apache tiles, trying to configure it in spring 4. But the templates, i am extending is not visible in my jsp page.For ex: If i am hitting url "/admin", then content of admin.jsp is visible, nothing else.
blow is the code snippet.
application-context.xml
<beans:bean id="viewResolver"
class="org.springframework.web.servlet.view.tiles3.TilesViewResolver" />
<beans:bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/layouts/views.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
views.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="DefaultTemplate"
template="/WEB-INF/views/template/SiteTemplate.jsp">
<put-attribute name="title" value="Home" />
<put-attribute name="header" value="/WEB-INF/views/template/header.jsp" />
<put-attribute name="body" value="This is body" />
<put-attribute name="footer" value="/WEB-INF/views/template/footer.jsp" />
</definition>
<definition name="admin" extends="DefaultTemplate">
<put-attribute name="body"
value="/WEB-INF/views/admin.jsp" />
</definition>
</tiles-definitions>
SiteTemplate.jsp
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>DCAT</title>
</head>
<body>
<div>
<!-- Header -->
<tiles:insertAttribute name="header" />
<!-- Body Page -->
<div>
<tiles:insertAttribute name="body" />
</div>
<!-- Footer Page -->
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>
Footer.jsp
<div>
<h2>Footer</h2>
</div>
Header.jsp
<div>
<h2>Header</h2>
</div>
admin.jsp
<div style="margin:10px;">
<h3>SpringMVC - Tiles3 Integration</h3>
<p>By:- Thita Nayak</p>
</div>
Admin controller
#Controller
public class AdminController {
private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
#RequestMapping(value = "/admin", method = RequestMethod.GET)
public String admin(){
return "admin";
}
}

I cannot see anything wrong with your code
The problem might be in the namespace declaration
Try to change beans:bean to beans if your namespace is as follow
<beans xmlns="http://www.springframework.org/schema/beans" ...

Related

Event only triggers if double click an element from sap.m.List

I have a SAPUI5 splitapp with a detail page. This detail page contains a list with ObjectListItems. I want to listen to a press/selection of this item, but I always have to press two times to an element, else the event does not get triggered.
Does anybody know what is the reason?
Thanks and best regards
Detail XML
<Page
id="myJobsPage"
title="{i18n>myJobsTitle}">
<List
id="myJobsMasterList"
inset="false"
items="{testkunden}">
<ObjectListItem
id="myJobsListItem"
visible="true"
title="{job}"
number="{offen}"
numberUnit="Euro"
press="onMyJobsListItem"
type="Active">
<!-- visible part -->
<ObjectAttribute
id="Gpart123"
text="Partner: {gpart}"
visible="true" />
<ObjectAttribute
id="Anrede123"
text="{anrede}"
visible="true" />
<ObjectAttribute
id="Name123"
text="{vorname} {nachname}"
visible="true" />
<ObjectAttribute
id="Strasse123"
text="{strasse} {hausnr}"
visible="true" />
</ObjectListItem>
<!-- <ObjectStatus text="{i18n>myJobsObjectStatus}" /> -->
</List>
</Page>
</mvc:View>
Controller
onMyJobsListItem: function(event){
console.log("only triggers if click twice");
};
UPDATE:
Splitapp Root View
<mvc:View
controllerName="mobile.splitapp.controller.App"
displayBlock="true"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m" >
<App id="app">
<SplitApp id="splitapp" >
<masterPages>
<mvc:XMLView viewName="mobile.splitapp.view.Master" id="master1" />
</masterPages>
<detailPages>
<mvc:XMLView viewName="mobile.splitapp.view.MyJobs" id="myJobsPage" />
<mvc:XMLView viewName="mobile.splitapp.view.DisconnectionOrder" id="disconnectionOrderPage" />
</detailPages>
</SplitApp>
</App>
</mvc:View>
Here is a running example of your code (see below of jsbin, and the updated jsbin) and it runs just fine! Since you did not post your "surrounding" code I cannot tell what's wrong. But as you can see in the example below the event is triggered directly after the first press...
Cann you see a difference to your code?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SAPUI5 single file template | nabisoft</title>
<script src="https://openui5beta.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-bindingSyntax="complex"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"></script>
<!-- use "sync" or change the code below if you have issues -->
<!-- XMLView -->
<script id="myXmlView" type="ui5/xmlview">
<mvc:View
controllerName="MyController"
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc">
<App>
<SplitApp>
<masterPages>
<Page
id="myJobsPage"
title="Master Page">
<List
id="myJobsMasterList"
inset="false"
items="{/Customers}">
<ObjectListItem
id="myJobsListItem"
visible="true"
title="{CompanyName}"
number="{offen}"
numberUnit="Euro"
press="onMyJobsListItem"
type="Active"/>
</List>
</Page>
</masterPages>
<detailPages>
<Page
title="Detail Page">
<List
inset="false"
items="{/Customers}">
<ObjectListItem
visible="true"
title="{CompanyName}"
number="{offen}"
numberUnit="Euro"
press="onMyJobsListItem"
type="Active"/>
</List>
</Page>
</detailPages>
</SplitApp>
</App>
</mvc:View>
</script>
<script>
sap.ui.getCore().attachInit(function () {
"use strict";
//### Controller ###
sap.ui.controller("MyController", {
onInit : function () {
this.getView().setModel(
new sap.ui.model.odata.v2.ODataModel("https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/", {
json : true,
useBatch : false
})
);
},
onMyJobsListItem: function(event){
alert("press");
}
});
//### THE APP: place the XMLView somewhere into DOM ###
sap.ui.xmlview({
viewContent : jQuery("#myXmlView").html()
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>

JSF/Primefaces How to include an .xhtml from another domain into your .xhtml

I am trying to include an xhtml which is on another domain (on the same server) inside my .xhtml.
The sample code is the following
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:outputStylesheet library="css" name="style.css" target="body" />
</h:head>
<h:body>
<p:layout id="page" fullPage="true">
<!-- North -->
<p:layoutUnit position="north" size="10%"
style="border: none !important">
</p:layoutUnit>
<!-- South -->
<p:layoutUnit position="south" size="5%" collapsible="true" gutter="0">
<h:outputText value="South unit Content." />
</p:layoutUnit>
<!-- West -->
<p:layoutUnit position="west" size="200" header="Menu"
collapsible="true" effect="slide" styleClass="menuBar">
<h:form id="form1">
<p:panelMenu>
<p:submenu label="Students">
<p:menuitem value="page1" update=":centerpanel"
actionListener="#{layoutController.setNavigation('page2.xhtml')}" />
<p:menuitem value="page2" update=":centerpanel"
actionListener="#{layoutController.setNavigation('http://localhost:8080/externalsite/newpage.xhtml')}" />
</p:submenu>
</p:panelMenu>
</h:form>
</p:layoutUnit>
<!-- Center -->
<p:layoutUnit id="center" position="center">
<h:panelGroup id="centerpanel" layout="block">
<ui:include id="include" src="#{layoutController.navigation}" />
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
So basically in the center layout unit I am trying to include the external .xhtml (which is on the same domain however).
JSF templates can be included only, if they are available within the same classloader.
If you want to embed an external page into your page, you need to user iframe.
For example:
<iframe src="http://www.primefaces.org/showcase/ui/home.jsf"/>
allows you to embed PrimeFaces showcase withing your page.
This is not possible. With the ui:include Tag you can only include Code Snippets from other xhtml files. What you are trying to do is accessing Code from another domain, but what you see in the final web app is only the generated HTML and Javascript Code. You cannot work with that in your application, as you have no access to the sourcecode.

JSF 2 template partial update [duplicate]

This question already has answers here:
How to ajax-refresh dynamic include content by navigation menu? (JSF SPA)
(3 answers)
Closed 5 years ago.
I have the following JSF 2 template Page with primefaces menu, I want to partially update the cenral centent of the page onclick of links from left Menu, I don't want to update the entire page.I have gone throu the posts in stackoverflow, they are suggetign that I should have a form name in the central_body_div, but I don't want to sepcify a form in the central_body_div, as the dynamically loaded page will have form with it's own name, I should be able to submit the form in the page appearing dynamically in central_body_div div.
First of all the Layout page itself not loading , giving the below exception.
Cannot find component with identifier "central_body_div" referenced from "leftMenuFormId:menuItem1".
Experts can you give a solution for this problem. would apprecite your replies.
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="cssLayout.css" library="css" />
<h:outputStylesheet name="default.css" library="css" />
<title> Lightweight Mediation - Secure Pages </title>
</h:head>
<h:body id="securebody">
<div id="top">
<ui:insert name="top">
<ui:include src="/secure/home/header.xhtml" />
</ui:insert>
</div>
<div id="content_holder">
<div id="left">
<ui:insert name="left">
<ui:include src="/secure/home/leftMenu.xhtml" />
</ui:insert>
</div>
<div id="central_body_div" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
<div id="bottom">
<ui:insert name="bottom">
<ui:include src="/secure/home/footer.xhtml" />
</ui:insert>
</div>
</h:body>
</f:view>
</html>
My leftMenu.xhtml content is below
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<ui:composition id="leftMenuCompositionId">
<h:form id="leftMenuFormId">
<p:menu id="lMenuId">
<p:menuitem id="menuItem1" value="page1" action="page1" update="central_body_div" partialSubmit="true"/>
<p:menuitem id="menuItem2" value="page2" action="page2" update="central_body_div" partialSubmit="true" />
</p:menu>
</h:form>
</ui:composition>
</h:body>
</html>
Change your code with following and try again,
leftMenu.xhtml
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<ui:composition id="leftMenuCompositionId">
<h:form id="leftMenuFormId">
<p:menu id="lMenuId">
<p:menuitem id="menuItem1" value="page1" action="page1" update=":form1:central_body_div" partialSubmit="true"/>
<p:menuitem id="menuItem2" value="page2" action="page2" update=":form1:central_body_div" partialSubmit="true" />
</p:menu>
</h:form>
</ui:composition>
</h:body>
and your template xhtml with,
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view contentType="text/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="cssLayout.css" library="css" />
<h:outputStylesheet name="default.css" library="css" />
<title> Lightweight Mediation - Secure Pages </title>
</h:head>
<h:body id="securebody">
<div id="top">
</div>
<div id="content_holder">
<div id="left">
<ui:insert name="left">
<ui:include src="leftMenu.xhtml" />
</ui:insert>
</div>
<h:form id="form1" >
<h:panelGroup id="central_body_div">
<script type="text/javascript">alert('Content Updated')</script>
<ui:insert name="content">Content</ui:insert>
</h:panelGroup>
</h:form>
</div>
<div id="bottom">
</div>
</h:body>
</f:view>
It's checked and working.
Warning! View build time vs view render time problem ahead!
The usual mistake here is performing navigation, or as you say, refreshing a central holder with <ui:insert>/<ui:define>, which is a view build tag, not a view render UI component. So it simply won't be recalculated on AJAX requests, as your component tree will be restored from view state, and will not be built afresh.
So, just don't do that mistake, by making AJAX navigation, which is defective in many ways (SEO, non-bookmarkability, not user friendliness, etc.) and perform navigation by the components designed for that, like <h:link>, or <p:menuItem> that's generating plain get as.
As per your comment you don't fully distinguish between navigation links and command links. The former are used to perform navigation only and generate bookmarkable a elements, while the latter are used to (partially) submit the form, do business job, and (partially) update the view, or perform navigation.
What you need to do is simply to distinguish between those cases. For navigation use <h:link>/<p:menuitem outcome="/your-view-id">, for POST actions, use <p:commandButton>/<p:menuitem action(listener)="#{bean.action(listener)}" instead.
In this case the templating structure doesn't matter as long as you don't expect tag handlers to be refreshed on AJAX requests.
I have placed the solution I arrived from the discussion in this post and reference from other posts. the page we are including can have different form names.
template.xhtml
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="cssLayout.css" library="css" />
<h:outputStylesheet name="default.css" library="css" />
<title> Lightweight Mediation - Secure Pages </title>
</h:head>
<h:body id="securebody">
<div id="top">
<ui:insert name="top">
<ui:include src="header.xhtml" />
</ui:insert>
</div>
<div id="content_holder">
<div id="left">
<ui:insert name="left">
<ui:include src="leftMenu.xhtml" />
</ui:insert>
</div>
<div id="center" class="left_content">
<h:panelGroup id="central_body_div">
<ui:include src="#{templateBean.page}.xhtml" />
</h:panelGroup>
</div>
</div>
<div id="bottom">
<ui:insert name="bottom">
<ui:include src="footer.xhtml" />
</ui:insert>
</div>
</h:body>
</f:view>
</html>
leftMenu.xhtml
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<ui:composition id="leftMenuCompositionId">
<h:form id="leftMenuFormId">
<f:ajax render=":central_body_div">
<h:commandLink value="page1" action="#{templateBean.setPage('page1')}" /><br></br>
<h:commandLink value="page2" action="#{templateBean.setPage('page2')}" />
</f:ajax>
</h:form>
</ui:composition>
</h:body>
</html>
Page 1
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<ui:composition>
<h1>Page One</h1>
</ui:composition>
</h:body>
</html>
Page 2
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<ui:composition >
<h:form id="form1" >
<h1>Page Two</h1>
</h:form>
</ui:composition>
</h:body>
</html>
package ae.co.gui.beans;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.event.ActionEvent;
#Named(value = "templateBean")
#SessionScoped
public class TemplateBean implements Serializable {
private String page;
public TemplateBean() {
}
#PostConstruct
public void init() {
this.page = "page1"; // Ensure that default is been set.
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
Late to the party... fixing an application for a client currently and face this issue. Didn't like the idea of adding a form. They use primefaces, not sure if this is only unique to them but
<p:commandButton ... update="#(:central_body_div)"/>
fixed the problem in my case.

Facelets: any library that ships templates?

Like in the title, is there any lib like PrimeFaces or RichFaces that is template-oriented?
I'm building my own including some fixed/liquid/elastic base layouts but I wonder if someone out there has already done this boring work.
UPDATE
i'm sorry, i haven't explained myself.
i'm talking about a sort of framework on framework made by a tree of templates (and optionally beans).
i'm currently using this root template, that is bundled in a jar file with some bean and , entity, for all my applications:
<!DOCTYPE html>
<html lang="#{localeBean.locale.language}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui"
xmlns:s="http://shapeitalia.com/jsf2"
xmlns:sc="http://java.sun.com/jsf/composite/shape">
<f:view locale="#{localeBean.locale}">
<h:head>
<title><ui:insert name="module"/> - <ui:insert name="title"/></title>
<link rel="shortcut icon" type="image/x-icon" href="#{resource['shape/favicon/shape.ico']}" />
<h:outputStylesheet library="shape" name="css/core.css" />
<h:outputStylesheet library="shape" name="css/fileicons.css" />
<h:outputScript library="shape" name="js/jquery.jsPlumb-1.3.15-all.js" />
<h:outputScript library="shape" name="js/core.js" />
</h:head>
<h:body>
<ui:debug hotkey="x" />
<p:growl id="messages" globalOnly="false" autoUpdate="true" showDetail="true" showSummary="true" />
<p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();" />
<p:dialog modal="true" widgetVar="statusDialog" header="loading..." resizable="false" closable="false">
<h:graphicImage library="shape" name="images/ajaxloadingbar.gif" />
</p:dialog>
<div>
<ui:insert name="header">
<h:form>
<s:panelGrid cellStyle="border: 0;">
<s:column style="text-align: left;">
<p:commandLink action="index" >
<h:graphicImage library="shape" name="images/shape.png" height="30px" style="vertical-align: middle; float: left; border: 0"/>
</p:commandLink>
</s:column>
<s:column style="text-align: right;">
<p:menuButton rendered="#{not empty request.userPrincipal}" value="#{request.userPrincipal.name}" style="float: right">
<p:menuitem actionListener="#{sessionBean.logout}" action="index" ajax="false" icon="ui-icon-power" value="#{bundle.logout}"/>
</p:menuButton>
</s:column>
</s:panelGrid>
</h:form>
</ui:insert>
</div>
<h:panelGroup rendered="#{not empty request.userPrincipal}">
<ui:insert name="content">insert content here</ui:insert>
</h:panelGroup>
<h:panelGroup rendered="#{empty request.userPrincipal}">
<h:form>
<p:panel header="login">
<h:panelGrid columns="3">
<h:outputLabel for="login_email" value="Email:" />
<h:outputLabel for="login_password" value="Password:" />
<h:panelGroup />
<p:inputText id="login_email" value="#{requestScope.email}" label="email" size="32"/>
<p:password id="login_password" value="#{requestScope.password}" label="password" feedback="false" size="32"/>
<p:commandButton value="Login" action="#{sessionBean.login}" icon="ui-icon ui-icon-check" ajax="false"/>
<p:message for="login_email" />
<p:message for="login_password" />
<h:panelGroup />
</h:panelGrid>
</p:panel>
</h:form>
</h:panelGroup>
<ui:insert name="external" />
</h:body>
</f:view>
</html>
and this is only the root one.
i'd like to know if is there someone who has already done a work like this and have bundled it
ok there is no such a thing.
the best out there are components like p:layout.

JSF/PrimeFaces - Template with <p:layout>

I need to create a layout like this but with all the containers on separated files, like:
top.xhtml
<p:layout fullPage="true">
<p:layoutUnit position="north" header="#{support.applicationTitle}">
<h:form>
<p:menubar>
<p:menuitem value="Quit" icon="ui-icon-close" action="#{userController.logOut()}" />
</p:menubar>
</h:form>
</p:layoutUnit>
Without the </p:layout> because it will be close on my footer.xhtml like:
<p:layoutUnit position="south" header="© 2012 - 2012 PORTAL DE IDEIAS">
</p:layoutUnit></p:layout>
I have tried with both files but I get a error telling me that I need to close the layout tag, what is correct, but how can I solve my problem? Is this the best approach for a template? And another problem is that the layout tag require a center layoutUnit
This is indeed not the right approach. Your template has to be XML well formed. I suggest to create a master template file instead if all you want is to only specify the center unit.
Taking the example on the showcase site, that should look like this:
/WEB-INF/templates/layout.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
>
<h:head>
<title>Title</title>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" header="Top" resizable="true" closable="true" collapsible="true">
<h:outputText value="Top unit content." />
</p:layoutUnit>
<p:layoutUnit position="south" size="100" header="Bottom" resizable="true" closable="true" collapsible="true">
<h:outputText value="South unit content." />
</p:layoutUnit>
<p:layoutUnit position="west" size="200" header="Left" resizable="true" closable="true" collapsible="true">
<h:form>
<ui:include src="../templates/themeMenu.xhtml" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="east" size="200" header="Right" resizable="true" closable="true" collapsible="true" effect="drop">
<h:outputText value="Right unit content." />
</p:layoutUnit>
<p:layoutUnit position="center">
<ui:insert name="content">Put default content here, if any.</ui:insert>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
Note the <ui:insert> in the center unit.
The template client can then just look like this:
/page.xhtml
<ui:composition template="/WEB-INF/templates/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
>
<ui:define name="content">
<p>Here goes your view-specific content.</p>
</ui:define>
</ui:composition>
which you open by http://example.com/contextname/page.xhtml.
See also:
How to include another XHTML in XHTML using JSF 2.0 Facelets?
If you're looking for live open source examples of advanced Facelets templating, you may find OmniFaces showcase app useful.