tiles mechanisms - is reproduced

Interface layout has been exploring a number of techniques found in TILES framework these days, looked at it and wrote a DEMO, integration with the JSF framework TILES. Out to share, please pointing 12.

Tiles framework provides a template mechanism, it will be the layout and content separation of duties. Allows you to first create the template, and then dynamically at run-time content into the layout. If you want under the internationalization, user preferences to customize your site, or simply to change the visual sense (which will happen sooner or later each site), you will find that the template is a powerful mechanism. Tiles framework has the following characteristics:

1 dynamically build and load the page

2 Screen Definition

3 support the tile and layout reuse

4 support the international

5 multi-channel

6 template capacity

Today, just wrote a basic function, implements a layout. Page header, page body, footer. Follow-up will continue to publish.

A write page header, page body, footer, three JSP files

1 `header.jsp

<% @ Page language = "java" contentType = "text / html; charset = gb2312"
pageEncoding = "gb2312"%>
<% @ Taglib uri = "http://java.sun.com/jsf/html" prefix = "h"%>
<% @ Taglib uri = "http://java.sun.com/jsf/core" prefix = "f"%>

<! DOCTYPE html PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Insert title here </ title>
</ Head>
<body>
<h:outputText value=" This is the page header section "> </ h: outputText>
</ Body>
</ Html>

2 body.jsp

<% @ Page language = "java" contentType = "text / html; charset = gb2312"
pageEncoding = "gb2312"%>
<% @ Taglib uri = "http://java.sun.com/jsf/html" prefix = "h"%>
<% @ Taglib uri = "http://java.sun.com/jsf/core" prefix = "f"%>

<! DOCTYPE html PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Insert title here </ title>
</ Head>
<body>
<h:outputText value=" This is the content section "> </ h: outputText>
</ Body>
</ Html>

3 `footer.jsp

<% @ Page language = "java" contentType = "text / html; charset = gb2312"
pageEncoding = "gb2312"%>
<% @ Taglib uri = "http://java.sun.com/jsf/html" prefix = "h"%>
<% @ Taglib uri = "http://java.sun.com/jsf/core" prefix = "f"%>

<! DOCTYPE html PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Insert title here </ title>
</ Head>
<body>
<h:outputText value=" This is part of the bottom of the tank "> </ h: outputText>
</ Body>
</ Html>

Second, the preparation of tiles profile tiles.xml;

<! DOCTYPE tiles-definitions PUBLIC
"- / / Apache Software Foundation / / DTD Tiles Configuration / / EN"
"Http://jakarta.apache.org/struts/dtds/tiles-config.dtd">
<tiles-definitions>
<definition name="hbflayout" path="/jsp/tiles/hbflayout.jsp">
<put name="header" value="/jsp/tiles/header.jsp" />
<put name="body" value="/jsp/tiles/body.jsp" />
<put name="footer" value="/jsp/tiles/footer.jsp"/>
</ Definition>
</ Tiles-definitions>

3 files in WEB.XML to increase TILES description:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" version = "2.5" xsi : schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name> javax.faces.CONFIG_FILES </ param-name>
<param-value> / WEB-INF/faces-config.xml </ param-value>
</ Context-param>
<filter>
<filter-name> encodingFilter </ filter-name>
<filter-class> filter.EncodingFilter </ filter-class>
<init-param>
<param-name> encoding </ param-name>
<param-value> GBK </ param-value>
</ Init-param>
<init-param>
<param-name> encodingShow </ param-name>
<param-value> true </ param-value>
</ Init-param>
</ Filter>
<filter-mapping>
<filter-name> encodingFilter </ filter-name>
<url-pattern> / * </ url-pattern>
</ Filter-mapping>
<servlet>
<servlet-name> Faces Servlet </ servlet-name>
<servlet-class> javax.faces.webapp.FacesServlet </ servlet-class>
<load-on-startup> 0 </ load-on-startup>
</ Servlet>
<servlet>
<servlet-name> TilesServet </ servlet-name>
<servlet-class> org.apache.struts.tiles.TilesServlet </ servlet-class>
<init-param>
<param-name> definitions-config </ param-name>
<param-value> / WEB-INF/tiles.xml </ param-value>
</ Init-param>
<init-param>
<param-name> definitions-parser-validate </ param-name>
<param-value> true </ param-value>
</ Init-param>
<load-on-startup> 2 </ 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.jsp </ welcome-file>
</ Welcome-file-list>
</ Web-app>

The preparation of the layout template file hbflayout.jsp 4

<% @ Page language = "java" contentType = "text / html; charset = gb2312"
pageEncoding = "gb2312"%>
<% @ Taglib uri = "http://java.sun.com/jsf/html" prefix = "h"%>
<% @ Taglib uri = "http://java.sun.com/jsf/core" prefix = "f"%>
<% @ Taglib uri = "/ WEB-INF/tld/struts-tiles.tld" prefix = "t"%>
<! DOCTYPE html PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Insert title here </ title>
</ Head>
<body> <br>

<f:view>
<table width="778" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<f:subview>
<t:insert attribute="header" flush="false"> </ t: insert>
</ F: subview>
</ Td>
</ Tr>
<tr>
<td>
<f:subview>
<t:insert attribute="body" flush="false"> </ t: insert>
</ F: subview>
</ Td>
</ Tr>
<tr>
<td>
<f:subview>
<t:insert attribute="footer" flush="false"> </ t: insert>
</ F: subview>
</ Td>
</ Tr>
</ Table>
</ F: view>
</ Body>
</ Html>

Five-page document written application templates tilespage.jsp

<% @ Page language = "java" contentType = "text / html; charset = gb2312"
pageEncoding = "gb2312"%>
<% @ Taglib uri = "/ WEB-INF/tld/struts-tiles.tld" prefix = "t"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Insert title here </ title>
</ Head>
<body> <br>
<t:insert definition="hbflayout" flush="true">
<t:put name="header" value="/jsp/tiles/header.jsp"> </ t: put>
<t:put name="body" value="/jsp/tiles/body.jsp"> </ t: put>
<t:put name="footer" value="/jsp/tiles/footer.jsp"> </ t: put>
</ T: insert>
</ Body>
</ Html>

Six-speed open your browser, http://192.168.2.52:8080/JSFTest/jsp/tiles/tilespage.faces, of course, write all their own access path.

It's that simple, for the first time one hour can handle that, and soon you like.

This article comes from CSDN blog, reproduced, please indicate the source: http://blog.csdn.net/sunhuiliang85/archive/2008/11/16/3313419.aspx

分类:Web 时间:2010-04-01 人气:376
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.297 (s). 14 q(s)