jsf - How can I use ui:define and ui:insert within the same ui:composition? -
i have ui:composition sits within template, , want repeat element both in template , composition itself.
here's example.
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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"> <h:head> <title>jsf 2.0 hello world</title> <link rel="stylesheet" type="text/css" href="css/style.css"/> </h:head> <h:body> <div class = "header"> <div class = "mylogo"></div> header <!-- want content logo defined within module.xhtml--> <ui:insert name = "content-logo"></ui:insert> </div> <div class = "content"> <ui:insert name = "content"></ui:insert> </div> <div class ="footer"> footer </div> </h:body> </html> module.xhtml
<!doctype html> <ui:composition 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:o="http://omnifaces.org/ui" template="template.xhtml"> <!-- define module content-logo here--> <ui:define name ="content-logo"> <div class ="another-logo"> foo</div> </ui:define> <ui:define name ="content"> <-- want display content-logo here--> <ui:insert name = "content-logo"/> <div class = "foo"> main content </div> </ui:define> </ui:composition> the defined content-logo display within template header fine - doesn't display in composition body. there way can make work without resorting copying html?
you can use ui:include in module.xhtml this
<ui:composition 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:o="http://omnifaces.org/ui" template="template.xhtml"> <!-- define module content-logo here--> <ui:define name ="content-logo"> <ui:include src="logo.xhtml"/> </ui:define> <ui:define name ="content"> <-- want display content-logo here--> <ui:include src="logo.xhtml"/> <div class = "foo"> main content </div> </ui:define> </ui:composition>
Comments
Post a Comment