1 / 6

IS-907 Java EE

IS-907 Java EE. Templating. Templates. When an application contains several pages with similar structure, duplication of code can be avoided through the use of templates The template defines the structure of the page with named parts The template may specify default content for each part

nrandall
Download Presentation

IS-907 Java EE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IS-907 Java EE Templating

  2. Templates • When an application contains several pages with similar structure, duplication of code can be avoided through the use of templates • The template defines the structure of the page with named parts • The template may specify default content for each part • Facelets which use the template must specify the named parts • Default content is used for unspecified parts Even Åby Larsen (even.larsen@uia.no) IS-102 Introduksjon

  3. Defining templates • The template is an ordinary facelet, except ui:insert tags are used to specify replacable parts: <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> <title><ui:insert name="title" /></title> <h:outputStylesheet library="css" name="is907.css" /> </h:head> <h:body> <div id="heading" class="heading"> <ui:insert name="heading”/> </div> ... Even Åby Larsen (even.larsen@uia.no) IS-102 Introduksjon

  4. Defining default content • The ui:include tag is used to include default content from other files: <div id="sidebar" class="menu"> <ui:insert name="sidebar"> <ui:include src="/views/common/sidebar.xhtml" /> </ui:insert> </div> Even Åby Larsen (even.larsen@uia.no) IS-102 Introduksjon

  5. Using templates <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:head> <title>IGNORED</title> </h:head> <h:body> <ui:composition template="/views/templates/layout.xhtml"> <ui:define name="title">IS-907 Netshop - Price List</ui:define> <ui:define name="content"> <h1>Price List</h1> ... </ui:define> </ui:composition> Even Åby Larsen (even.larsen@uia.no) IS-102 Introduksjon

  6. Using templates • Facelets refer to templates with a ui:composition tag • and specify the parts with ui:define tags • Only the contents of the ui:composition tag are used • the rest of the file is ignored • the structure of the page is taken from the template • Included files (e.g. default parts) are treated the same way: • Only the contents of the ui:composition tag are used Even Åby Larsen (even.larsen@uia.no) IS-102 Introduksjon

More Related