Facelets template in another template

I would like to use the Facelets template in another template. I currently have a basic template, which so far has been sufficient for all the pages I have made. It has a top and a content area.

At the top there is a logo, menu, input / output functions, and the content area shows, well, the content.

Now I need to make another page (to save user profile information), where I would like to have a menu on the left and show the result to the right. This page should be inserted into the content area of ​​the base template.

Is it possible to create a new template that defines these two areas (profile_left and profile_content) and somehow use the basic template?

I see no reason why I couldn’t just copy the code into the base template and add the new “defines” that I want (profile_left and profile_content), but I'm still wondering if I can continue to use the original base template.

+4
source share
1 answer

You can extend from the templates as deep as you want. It’s not true that you can only apply to one template or something that you think.

For instance:

/WEB-INF/templates/base.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" > <h:head> <title><ui:insert name="title">Default title</ui:insert></title> </h:head> <h:body> <div id="header">Header</div> <div id="menu">Menu</div> <div id="content"><ui:insert name="content">Default content</ui:insert></div> <div id="footer">Footer</div> </h:body> </html> 

/WEB-INF/templates/profile.xhtml

 <ui:composition template="/WEB-INF/templates/base.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" > <ui:define name="content"> <div id="profile_left"><ui:insert name="profile_left" /></div> <div id="profile_right"><ui:insert name="profile_right" /></div> </ui:define> </ui:composition> 

/user.xhtml

 <ui:composition template="/WEB-INF/templates/profile.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" > <ui:define name="title">User profile</ui:define> <ui:define name="profile_left"> Profile left. </ui:define> <ui:define name="profile_right"> Profile right. </ui:define> </ui:composition> 

See also:

How to include another XHTML in XHTML using JSF 2.0 Facelets?

+8
source

Source: https://habr.com/ru/post/1436626/


All Articles