
This hands-on lab assumes you have some basic knowledge or
programming experience on the following technologies.
Before you begin, you need to install the following software on your
computer.
Learning points:
0. Start NetBeans IDE.
1. Open core-book-viewer
NetBeans project.
2. Build and run core-book-viewer project.

| <html> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <f:view> <f:loadBundle basename="com.corejsf.messages" var="msgs"/> <head> <link href="styles.css" rel="stylesheet" type="text/css"/> <title><h:outputText value="#{msgs.bookWindowTitle}"/></title> </head> <body> <h:form> <h:panelGrid columns="2" styleClass="book" columnClasses="menuColumn, chapterColumn"> <f:facet name="header"> <h:panelGrid columns="1" styleClass="bookHeader"> <h:graphicImage value="#{book.image}"/> <h:outputText value="#{msgs[book.titleKey]}" styleClass='bookTitle'/> <hr/> </h:panelGrid> </f:facet> <h:dataTable value="#{book.chapterKeys}" var="chapterKey" styleClass="links" columnClasses="linksColumn"> <h:column> <h:commandLink> <h:outputText value="#{msgs[chapterKey]}"/> <f:param name="chapter" value="#{chapterKey}"/> </h:commandLink> </h:column> </h:dataTable> <c:import url="${param.chapter}.html"/> </h:panelGrid> </h:form> </body> </f:view> </html> |
| <h2> CHAPTER I </h2> <h3> Down the Rabbit-Hole </h3> <p> Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?' <p> |
In this exercise, you have built
and run a ready-to-build-and-run "core-book-viewer"
sample
application to get a sense how the application works.
1. Open core-book-viewer-include
NetBeans project.
2. Build and run core-book-viewer-include project.

| <html> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <f:view> <f:loadBundle basename="com.corejsf.messages" var="msgs"/> <head> <link href="styles.css" rel="stylesheet" type="text/css"/> <title><h:outputText value="#{msgs.bookWindowTitle}"/></title> </head> <body> <h:form> <h:panelGrid columns="2" styleClass="book" columnClasses="menuColumn, chapterColumn"> <f:facet name="header"> <f:subview id="header"> <c:import url="/bookHeader.jsp"/> </f:subview> </f:facet> <f:subview id="menu"> <c:import url="/bookMenu.jsp"/> </f:subview> <c:import url="/bookContent.jsp"/> </h:panelGrid> </h:form> </body> </f:view> </html> |
In this exercise, you have built
and run a ready-to-build-and-run "core-book-viewer-include"
sample
application to get a sense how the application works.
1. Open core-book-viewer-tiles
NetBeans project.
2. Remove broken references and add
library files.
3. Build and run core-book-viewer-tiles project.
| <?xml version="1.0"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <servlet> <servlet-name>Tiles Servlet</servlet-name> <servlet-class>org.apache.tiles.servlets.TilesServlet</servlet-class> <init-param> <param-name>definitions-config</param-name> <param-value>/WEB-INF/tiles.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app> |
| <!DOCTYPE tiles-definitions
PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration//EN" "http://jakarta.apache.org/struts/dtds/tiles-config.dtd"> <tiles-definitions> <definition name="book" path="/headerMenuContentLayout.jsp"> <put name="gridClass" value="headerMenuContent"/> <put name="headerClass" value="header"/> <put name="menuColumnClass" value="menuColumn"/> <put name="contentColumnClass" value="contentColumn"/> <put name="header" value="/bookHeader.jsp"/> <put name="menu" value="/bookMenu.jsp"/> <put name="content" value="/bookContent.jsp"/> </definition> </tiles-definitions> |
| <%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://jakarta.apache.org/tiles" prefix="tiles" %> <tiles:importAttribute scope="request"/> <h:panelGrid columns="2" styleClass="#{gridClass}" headerClass="#{headerClass}" columnClasses="#{menuColumnClass}, #{contentColumnClass}"> <f:facet name="header"> <f:subview id="header"> <tiles:insert attribute="header" flush="false"/> </f:subview> </f:facet> <f:subview id="menu"> <tiles:insert attribute="menu" flush="false"/> </f:subview> <f:subview id="content"> <tiles:insert attribute="content" flush="false"/> </f:subview> </h:panelGrid> |
| <html> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://jakarta.apache.org/tiles" prefix="tiles" %> <f:view> <f:loadBundle basename="com.corejsf.messages" var="msgs"/> <head> <link href="styles.css" rel="stylesheet" type="text/css"/> <title><h:outputText value="#{msgs.bookWindowTitle}"/></title> </head> <body> <f:subview id="book"> <h:form> <tiles:insert definition="book" flush="false"/> </h:form> </f:subview> </body> </f:view> </html> |
1. Open core-book-viewer-tiles-extends
NetBeans project.
2. Add library files.
2. Build and run core-book-viewer-tiles-extends project.
| <!DOCTYPE tiles-definitions
PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration//EN" "http://jakarta.apache.org/struts/dtds/tiles-config.dtd"> <tiles-definitions> <definition name="header-menu-content" path="/headerMenuContentLayout.jsp"> <put name="gridClass" value="headerMenuContent"/> <put name="headerClass" value="header"/> <put name="menuColumnClass" value="menuColumn"/> <put name="contentColumnClass" value="contentColumn"/> </definition> <definition name="book" extends="header-menu-content"> <put name="header" value="/bookHeader.jsp"/> <put name="menu" value="/bookMenu.jsp"/> <put name="content" value="/bookContent.jsp"/> </definition> </tiles-definitions> |
1. Open core-library
NetBeans project.
2. Add library files.
3. Build and run core-library project.


| <html> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://jakarta.apache.org/tiles" prefix="tiles" %> <f:view> <f:loadBundle basename="com.corejsf.messages" var="msgs"/> <head> <link href="styles.css" rel="stylesheet" type="text/css"/> <title><h:outputText value="#{msgs.libraryWindowTitle}"/></title> </head> <body> <f:subview id="library"> <h:form> <tiles:insert definition="library" flush="false"/> </h:form> </f:subview> </body> </f:view> </html> |
| <?xml version="1.0"
encoding="ISO-8859-1" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "http://struts.apache.org/dtds/tiles-config_1_1.dtd"> <tiles-definitions> <definition name="menu-header-content" path="/headerMenuContentLayout.jsp"> <put name="gridClass" value="headerMenuContent"/> <put name="headerClass" value="header"/> <put name="menuColumnClass" value="menuColumn"/> <put name="contentColumnClass" value="contentColumn"/> </definition> <definition name="book" extends="menu-header-content"> <put name="header" value="/bookHeader.jsp"/> <put name="menu" value="/bookMenu.jsp"/> <put name="content" value="/bookContent.jsp"/> </definition> <definition name="library" path="/libraryLayout.jsp" controllerClass="com.corejsf.LibraryTileController"> <put name="header" value="/bookSelector.jsp"/> <put name="book" value="book"/> </definition> </tiles-definitions> |
| <%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://jakarta.apache.org/tiles" prefix="tiles" %> <h:panelGrid columns="1" styleClass="book" headerClass="libraryHeader"> <f:facet name="header"> <f:subview id="header"> <tiles:insert attribute="header" flush="false"/> </f:subview> </f:facet> <f:subview id="book"> <tiles:insert attribute="book" flush="false"/> </f:subview> </h:panelGrid> |
| import
javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.tiles.ComponentContext; import org.apache.tiles.Controller; public class LibraryTileController implements Controller { public void execute(ComponentContext tilesContext, HttpServletRequest request, HttpServletResponse response, ServletContext context) throws IOException, ServletException { HttpSession session = request.getSession(); String chapter = (String) request.getParameter("chapter"); session.setAttribute("chapter", chapter == null || "".equals(chapter) ? "chapter1" : chapter); Library library = (Library) session.getAttribute("library"); if(library == null) { library = new Library(); session.setAttribute("library", library); } Book selectedBook = library.getSelectedBook(); if(selectedBook != null) { session.setAttribute("book", selectedBook); } } public void perform(ComponentContext tilesContext, HttpServletRequest request, HttpServletResponse response, ServletContext context) throws IOException, ServletException { HttpSession session = request.getSession(); execute(tilesContext, request, response, context); } } |