Today I attended a presentation of Peter Koletzke at ODTUG, where he explains that jsf templating is possible in jdeveloper 10.1.3, so let's give it a try. Steve Muench wrote a
nice article in the oracle magazine over how you can do it in 11G. In 10.1.3 this is called regions and JHeadstart is using this for branding, menu tabs etc. In this blog I will show you the basics how it works. The First step is to know what to template in your application. In my case I want to template the header of the page and the menu buttons. We need to make a new file called region-metadata.xml and put this in the web-inf folder. In this file we create templates entries.
<?xml version="1.0" encoding="windows-1252"?>
<faces-config xmlns="http://java.sun.com/JSF/Configuration">
<component>
<component-type>nl.ordina.jsf.templating.Header</component-type>
<component-class>oracle.adf.view.faces.component.UIXRegion</component-class>
<component-extension>
<region-jsp-ui-def>/regions/header.jspx</region-jsp-ui-def>
</component-extension>
</component>
<component>
<component-type>nl.ordina.jsf.templating.Menu</component-type>
<component-class>oracle.adf.view.faces.component.UIXRegion</component-class>
<attribute>
<attribute-name>name</attribute-name>
<attribute-class>java.lang.String</attribute-class>
<default-value>empty</default-value>
<attribute-extension>
<required>false</required>
</attribute-extension>
</attribute>
<component-extension>
<region-jsp-ui-def>/regions/menu.jspx</region-jsp-ui-def>
</component-extension>
</component>
</faces-config>
The things you should know, give an unique value to the component-type element of the template component.
This is important because your need this value to reference it in the jsf page. What is the path to region jsf page, this is defined in the region-jsp-ui-def and do I need to pass variables from the.Now we can create the menu template jsf page
<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
xmlns:af="http://xmlns.oracle.com/adf/faces">
<jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
<af:regionDef var="menu">
<af:menuBar>
<af:commandMenuItem text="#{menu.name}" action="start" />
</af:menuBar>
</af:regionDef>
</jsp:root>
In the template page we have to define the regionDef component and by using the attribute var we can reference the template variables defined in the region-metadata.xml. In my case I can use #{menu.name} to get value of the main page.
<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:af="http://xmlns.oracle.com/adf/faces">
<jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
<jsp:directive.page contentType="text/html;charset=windows-1252"/>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>main</title>
</head>
<body>
<af:messages/>
<h:form>
<af:panelPage title="Mainpage">
<f:facet name="menuGlobal">
<af:region id="menu" regionType="nl.ordina.jsf.templating.Menu">
<af:attribute name="name" value="MainPage"/>
</af:region>
</f:facet>
<f:facet name="branding">
<af:region id="header" regionType="nl.ordina.jsf.templating.Header"/>
</f:facet>
<af:outputText value="bodytext"/>
</af:panelPage>
</h:form>
</body>
</html>
</f:view>
</jsp:root>
In the main page we have to use a region component to reference the template page. The value of the regionType attribute must be the same as the region-metadata.xml. Because this template has also an attribute, we have to define an child element with the name attribute. Make sure if you using a template variable then you need create the region component inside a panel component else the variables are empty. You are now ready to run the main page