開發好控件的管理:
對於自己開發的控件,我們要把它管理起來,以便在以後的開發流程中使用,
我的在這裏談談如何管理自己開發的控件的問題。具體的方法就是把它歸檔到一個library
裏去。
比如我開發了一些控件,我就把它歸檔到一個叫Common.library的xml文檔裏去。
Common.library
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd>
<library-specification>
<!-- Library Section-->
<library id="contrib" specification-path="/org/apache/tapestry/contrib/Contrib.library"/>
<library id="basic" specification-path="/com/ht/components/basic/Basic.library"/>
<!-- Add more libraries here.-->
<!-- End of Library Section-->
<component-type type="TabPanel" specification-path="tabpanel/TabPanel.jwc"/>
<component-type type="Border" specification-path="border/Border.jwc"/>
<component-type type="ToolItem" specification-path="toolbar/ToolItem.jwc"/>
<component-type type="ToolBar" specification-path="toolbar/ToolBar.jwc"/>
<component-type type="AnchorDirect" specification-path="tree/components/AnchorDirect.jwc"/>
<component-type type="TreeDataView" specification-path="tree/components/TreeDataView.jwc"/>
<component-type type="TreeHeaders" specification-path="tree/components/TreeHeaders.jwc"/>
<component-type type="TreeNodeView" specification-path="tree/components/TreeNodeView.jwc"/>
<component-type type="TreeView" specification-path="tree/components/TreeView.jwc"/>
<component-type type="FileList" specification-path="table/FileList.jwc"/>
<component-type type="WrapInsertText" specification-path="wraptext/WrapInsertText.jwc"/>
<component-type type="HighlightInsertText" specification-path="highlight/HighlightInsertText.jwc"/>
<component-type type="DefaultTableColumnComponent" specification-path="table/DefaultTableColumnComponent.jwc"/>
<component-type type="AlignRightTableColumnComponent" specification-path="table/AlignRightTableColumnComponent.jwc"/>
<component-type type="DefaultTableColumns" specification-path="table/DefaultTableColumns.jwc"/>
</library-specification>
<libray-specification>包含兩種元素
一種是library<library id="contrib" specification-path="/org/apache/tapestry/contrib/Contrib.library"/>
因爲如果被歸檔的控件還引用到其他的被歸檔的控件(控件庫),就必須在這裏包含進來。
例外一種是
<component-type type="ToolBar" specification-path="toolbar/ToolBar.jwc"/>
就是被歸檔的控件項定義,這句我們應該有印象,這個控件就是我們前面討論的ToolBar
注意這個specification-path是相對路徑。
比如我的Common.library位於com.ht.components包內,而那個ToolBar.jwc位於com.ht.components.toolbar包內。
頁面的開發:
我的Web Application只支持英語和簡體中文,以開發Home頁爲例,我所需要新建的文件
爲:
Home.java
Home.page
Home.properties
Home_zh_CN.properties
它們都位於com.ht.home包內,對應的目錄爲F:\myproject\TapestryExmaple\src\
com\ht\home
Home.html
它位於context下home目錄內,對應的目錄爲F:\myproject\TapestryExmaple\context\home
我的例程爲:
Home.java
package com.ht.home;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry.engine.AbstractEngine;
import org.apache.tapestry.html.BasePage;
import com.ht.web.PatientRecordBasePage;
import com.ht.web.PatientRecordEngine;
import com.ht.components.tabpanel.*;
/**
* @author Hery Tang
*
* Creation Date 2003-9-22
* Version 1.0
*/
public class Home extends PatientRecordBasePage {
public void logout() {
PatientRecordEngine engine = (PatientRecordEngine) getEngine();
engine.logout();
}
}
Home.page
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd>
<page-specification class="com.ht.home.Home">
<component id="border" type="common:Border">
<message-binding name="title" key="title"/>
<binding name="styleSheet" expression="assets.test"/>
</component>
<context-asset name="$template" path="home/Home.html"/>
<context-asset name="menuIcon" path="home/images/homeIcon.gif"/>
<context-asset name="test" path="home/css/test.css"/>
</page-specification>
Home_zh_CN.properties
menuText=首頁
title=首頁
actionListener.logout.menuText=註銷
welcome=歡迎
welcomeDetail=歡迎使用web病歷管理系統,這是一套基於網絡的B/S結構的病歷管理服務系統,功能新穎,界面友好,歡迎使用。
Home.properties
title=Home
menuText=Home
actionListener.logout.menuText=Logout
welcome=Welcome
welcomeDetail=Welcome to use Web Document Manage System.This system based on B/S network structure, it provides internal documents' management for your company. It's document directory organized as that: a department as a unit, departments can share documents each other. Meanwhile, it provides detailed document version control.
Home.html
<span jwcid="border">
<table align="center" width="100%" height="100">
<tr>
<!-- ========================== START MID COL ======================= -->
<td VALIGN="TOP" width='100%'>
<table width='100%' cellpadding='0' cellspacing='0' border='0'>
<tr>
<td width='10'><img src='home/images/pixel.gif' width='10' height='1' alt='-'></td>
<td width='100%'><img src='home/images/welcome_head_icon.gif' ALIGN="BOTTOM" WIDTH="16" HEIGHT="16" ALT="Welcome!"> <font class='h2' style='color: #080c77;'><span key="welcome">Welcome</span></font></td>
<td width='10'><img src='home/images/pixel.gif' width='10' height='1' alt='-'></td>
</tr>
<tr>
<td height='5' colspan='3' valign='top'><img src='home/images/head_home_line.gif' width='254' height='5' alt='-'></td>
</tr>
<tr>
<td height='5' colspan='3' bgcolor='#ffffff'><img src='home/images/pixel.gif' width='1' height='5' alt='-'></td>
</tr>
<tr>
<td width='10' bgcolor='#ffffff'><img src='home/images/pixel.gif' width='10' height='1' alt='-'></td>
<td width='100%' bgcolor='#ffffff'>
<span key="welcomeDetail">Welcome to use Web Document Manage System.This system based on B/S network structure, it provides internal documents' management for your company. It's document directory organized as that: a department as a unit, departments can share documents each other. Meanwhile, it provides detailed document version control.</span>
</td>
<td width='10' bgcolor='#ffffff'><img src='home/images/pixel.gif' width='10' height='1' alt='-'></td>
</tr>
<tr>
<td height='5' colspan='3' bgcolor='#ffffff'><img src='home/images/pixel.gif' width='1' height='5' alt='-'></td>
</tr>
</table>
</td>
</tr>
</table>
</span>
對於頁面的開發,有幾個值得討論的問題,
一 框架化的頁面怎麼實現
這個很簡單,你只要開發一個控件,預先定義好一個顯示框架,我就是這麼做的,我開發了一個叫Border的控件,然後把變動的顯示作爲Border可變的內容輸出。
你看我的 Home.html,它被<span jwcid="border">**</span>所包圍,我的Border控件負責
顯示每頁確定的內容,變動的則只在Border的一個預定的區域顯示。
二 國際化怎麼辦
Tapestry國際化非常簡單,例如英文我要顯示welcome,中文顯示歡迎
只須這樣就行:
<span key="welcome">Welcome</span>(中間的Welcome是預覽hmtl用的沒有
別的意義),然後你在home.properties設定key-value對爲: welcome=Welcome
在Home_zh_CN.properties設定爲: welcome=歡迎,不過最後打包時你要將你的
Home_zh_CN.properties用jdk的bin目錄下的native2ascii命令轉化一下,不然會
顯示成亂碼。
我們來分析一下Home.page
<page-specification class="com.ht.home.Home">
聲明本頁對應的class爲com.ht.home.Home
<component id="border" type="common:Border">
<message-binding name="title" key="title"/>
<binding name="styleSheet" expression="assets.test"/>
</component>
聲明並配置一個Border類型的控件
<message-binding name="title" key="title"/>
指定了本頁的title
binding name="styleSheet" expression="assets.test"/>
指定了本頁應用的StyleSheet資源
<context-asset name="$template" path="home/Home.html"/>
指定了Home頁的模版爲home/Home.html
<context-asset name="menuIcon" path="home/images/homeIcon.gif"/>
聲明一個context-asset(圖標)
<context-asset name="test" path="home/css/test.css"/>
聲明一個context-asset(Stylesheet),被上面的Border控件引用
最後講講劃分子模塊的問題:
比如我的Web Application包含兩個子模快home, patientrecord,
home對應的包爲com.ht.home,絕對路徑爲F:\myproject\TapestryExmaple\src\
com\ht\home,對應的context目錄爲home,絕對路徑爲F:\myproject\
TapestryExmaple\context\home
patientrecord對應的包爲com.ht.patientrecord,絕對路徑爲F:\myproject\TapestryExmaple\src\com\ht\patientrecord,
對應的context目錄爲patientrecord,絕對路徑爲F:\myproject\
TapestryExmaple\context\patientrecord
home模塊下的頁面有
Home,Register,Login,About,PaitentRecordException,SecurityException
patientrecord模塊下的頁面有
Browser,Create,AddTreatment,AddExamination,AddOperation,AddOperationVisit,AddOperationVisit,AddComment
我需要將這些頁面歸檔,所以對應home子模塊有Home.libray,對應於patientrecord
有PatientRecord.library
Home.library的位於com.ht.home包下,
PatientRecord.library位於com.ht.patientrecord包下
他們分別爲
Home.library
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd>
<library-specification>
<!-- Library Section-->
<library id="contrib" specification-path="/org/apache/tapestry/contrib/Contrib.library"/>
<library id="common" specification-path="/com/ht/components/Common.library"/>
<!-- Add more libraries here.-->
<!-- End of Library Section-->
<page name="Home" specification-path="Home.page"/>
<page name="Register" specification-path="Register.page"/>
<page name="Login" specification-path="Login.page"/>
<page name="About" specification-path="About.page"/>
<page name="PaitentRecordException" specification-path="PRException.page"/>
<page name="SecurityException" specification-path="SecurityExceptionPage.page"/>
</library-specification>
PatientRecord.library
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd>
<library-specification>
<!-- Library Section-->
<library id="contrib" specification-path="/org/apache/tapestry/contrib/Contrib.library"/>
<library id="common" specification-path="/com/ht/components/Common.library"/>
<!-- Add more libraries here.-->
<!-- End of Library Section-->
<page name="Browser" specification-path="Browser.page"/>
<page name="Create" specification-path="Create.page"/>
<page name="AddTreatment" specification-path="AddTreatment.page"/>
<page name="AddExamination" specification-path="AddExamination.page"/>
<page name="AddOperation" specification-path="AddOperation.page"/>
<page name="AddOperationVisit" specification-path="AddOperationVisit.page"/>
<page name="AddComment" specification-path="AddComment.page"/>
</library-specification>
最後我們再看一下patientrecord.application這個Tapestry Web 應用核心配置文件:
patientrecord.application
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd>
<application name="Patient Record System" engine-class="com.ht.web.PatientRecordEngine">
<property name="org.apache.tapestry.visit-class" value="com.ht.web.VisitorState"/>
<property name="com.ht.home-page" value="home:Home"/>
<!--<property name="com.ht.exception-page" value="home:PaitentRecordException"/>-->
<property name="com.ht.security-exception-page" value="home:SecurityExceptionPage"/>
<!--Overrided the Home Service to let us to decide which page will be the home page-->
<service name="home" class="com.ht.web.HomeService"/>
<library id="home" specification-path="/com/ht/home/Home.library"/>
<library id="patientrecord" specification-path="/com/ht/patientrecord/PatientRecord.library"/>
</application>
看看最後兩行
<library id="home" specification-path="/com/ht/home/Home.library"/>
<library id="patientrecord" specification-path="/com/ht/patientrecord/PatientRecord.library"/>
我們把那兩個libary文件包含進來了,分別對應id爲home, patientrecord
,我們要在程序裏激活Home頁,則只需
得一個IRequestCycle對象cycle
cycle.activate("home:Home");
注意“home:Home“,前一個home是library name,後一個是Page name.這是Tapestry
自定義的名字訪問法則。
以上,是我開發Tapestry Web Application的一點心得體會,歡迎討論批評.
管理自定義開發的組件[轉]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.