myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Spencer <p...@intekon.com>
Subject Content of <ui:define> variable not appearing in <ui:include> include fragment.
Date Tue, 01 Jul 2014 14:29:21 GMT
Using MyFaces 2.2.3

The intent is for the contents of the <ui:define> variable page_title to appear both
in the browser title bar and in the page’s content header area while using a common template
across many pages.  The content header area is displayed in the <body> of the page and
is there to give each page a consistent look.

In the example below, “My Page1 Title” appears as the title of the page1.jsp, but not
in the header content of the page.

Why does the <ui:define> variable page_title evaluate to blank/null in includes pages?

Is there a better way to accomplish the intended behavior?


***
* Page1.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:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
	<ui:composition template="/template/commonLayout.xhtml">
		<ui:define name=“page_title”>My Page1 Title</ui:define>
		<ui:define name=“content">
			<f:view transient=“true”>
                          <h1>Page 1</h1>
			</f:view>
		</ui:define>

	</ui:composition>
</h:body>
</html>



***
* commonLayout.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:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<h:outputStylesheet library="css" name="default.css" />
	<h:outputStylesheet library="css" name="cssLayout.css" />
	<title><ui:insert name="page_title" /></title>
</h:head>

<h:body>
	<ui:debug />
	<div id="page">
		<div id="top">
			<ui:insert name="header">
				<ui:include src="/template/commonHeader.xhtml"/>
			</ui:insert>
		</div>
		<div>
			<div id="left">
				<ui:insert name="menu">
					<ui:include src="/template/commonMenuLeft.xhtml" />
				</ui:insert>
			</div>

			<div id="content">
				<ui:insert name="content">
					<ui:include src="/template/commonContent.xhtml"/>
				</ui:insert>
			</div>
			<ui:debug></ui:debug>
		</div>
		<div id="bottom">
			<ui:insert name="footer">
				<ui:include src="/template/commonFooter.xhtml" />
			</ui:insert>
		</div>

	</div>
</h:body>
</html>

***
* commonHeader.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">
<body>
	<ui:component>
		<h1 style="text-align: center; color: black; background-color: white;">
			<ui:insert name="page_title" />
		</h1>
	</ui:component>
</body>
</html>


Paul Spencer


Mime
View raw message