Tiles配置与基本配置文件介绍
时间:2007-08-07 来源:sdwsyjp
Tiles有一个配置文件:tiles-defs.xml
tiles-defs.xml定义了每一个页面的组成元素和形式。
下面我将说明如下所示的一个tiles-defs.xml文件
tiles-defs.xml
-----------------------------------------------------------------
<tiles-definitions>
<!--定义/layout/ mainLayout.jsp的组成名称为bugbase.mainLayout -->
<definition name="bugbase.mainLayout" path="/layout/mainLayout.jsp">
<put name="title" value="质量管理系统" /> //标题
<put name="logo" value="/WEB-INF/pages/main/logo.jsp" />//logo左上角的标志
<put name="mainMenu" value="/WEB-INF/pages/main/mainMenu.jsp" />
Struts-config.xml
-----------------------------------------------------------------
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/plugin/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-parser-validate"
value="true" />
</plug-in>
//主菜单不发生变化
<put name="messages" value="/common/messages.jsp" /> //错误信息
<put name="submenu" value="/WEB-INF/pages/main/testManageSubMenu.jsp" />
//子菜单随模块的变化而变化
</definition>
这里的title是标题,logo是界面上最左上角的标志,质量管理系统有两级菜单,mainMenu是主菜单,是不变的,而subMenu是子菜单,六个模块就有六个子菜单,是随模块而变化的。messages是错误信息。
<!--定义common.testManage,继承bugbase.mainLayout -->
<definition extends="bugbase.mainLayout" name="common.setting">
<put name="submenu" value="/WEB-INF/pages/main/settingSubMenu.jsp" />
<!--以上的元素将替换bugbase.mainLayout中的元素-->
</definition>
这里的common.testManage是测试管理模块的意思,这就是一个模块对应一个subMenu。
<!—定义setting.projectInfo,继承common.setting -->
<definition extends="common.setting" name="setting.projectInfo">
<put name="leftBody" value="/WEB-INF/pages/common/body/projectinfoleftbd.jsp" />
<put name="rightBody" value="/WEB-INF/pages/common/body/projectinforightbd.jsp" />
</definition>
这是说一个模块下有多个功能点,每个功能点下的左侧菜单是相同的,因此leftBody就是这个左侧菜单,变化的只是rightBody右侧部分而已。下面还有详解。
/layout/ mainLayout.jsp
-----------------------------------------------------------------
…
<html>
<head>
<title><tiles:getAsString name="title" /></title>
…
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="mainInit()" >
<table cellpadding="0" cellspacing="0" class="LogoTable" id="01" >
<tr valign="bottom">
<tiles:insert attribute="logo" />
<tiles:insert attribute="mainMenu" />
</tr>
<tr valign="top" >
<tiles:insert attribute="submenu" />
</tr>
</table>
<table class="MainTable" cellpadding="1" cellspacing="1">
<tr class="TrMain">
<td width="225" >
<tiles:insert attribute="leftBody" />
</td>
<td width="775">
<table>
<tiles:insert attribute="messages" />
</table>
<tiles:insert attribute="rightBody" />
</td>
</tr>
</table>
</body>
</html>
在web.xml里面配置tiles对应的taglib的配置如下:
web.xml
-----------------------------------------------------------------
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
在struts-config.xml里面配置tiles-defs.xml
Struts-config.xml
-----------------------------------------------------------------
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/plugin/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-parser-validate"
value="true" />
</plug-in>
tiles-defs.xml定义了每一个页面的组成元素和形式。
下面我将说明如下所示的一个tiles-defs.xml文件
tiles-defs.xml
-----------------------------------------------------------------
<tiles-definitions>
<!--定义/layout/ mainLayout.jsp的组成名称为bugbase.mainLayout -->
<definition name="bugbase.mainLayout" path="/layout/mainLayout.jsp">
<put name="title" value="质量管理系统" /> //标题
<put name="logo" value="/WEB-INF/pages/main/logo.jsp" />//logo左上角的标志
<put name="mainMenu" value="/WEB-INF/pages/main/mainMenu.jsp" />
Struts-config.xml
-----------------------------------------------------------------
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/plugin/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-parser-validate"
value="true" />
</plug-in>
//主菜单不发生变化
<put name="messages" value="/common/messages.jsp" /> //错误信息
<put name="submenu" value="/WEB-INF/pages/main/testManageSubMenu.jsp" />
//子菜单随模块的变化而变化
</definition>
这里的title是标题,logo是界面上最左上角的标志,质量管理系统有两级菜单,mainMenu是主菜单,是不变的,而subMenu是子菜单,六个模块就有六个子菜单,是随模块而变化的。messages是错误信息。
<!--定义common.testManage,继承bugbase.mainLayout -->
<definition extends="bugbase.mainLayout" name="common.setting">
<put name="submenu" value="/WEB-INF/pages/main/settingSubMenu.jsp" />
<!--以上的元素将替换bugbase.mainLayout中的元素-->
</definition>
这里的common.testManage是测试管理模块的意思,这就是一个模块对应一个subMenu。
<!—定义setting.projectInfo,继承common.setting -->
<definition extends="common.setting" name="setting.projectInfo">
<put name="leftBody" value="/WEB-INF/pages/common/body/projectinfoleftbd.jsp" />
<put name="rightBody" value="/WEB-INF/pages/common/body/projectinforightbd.jsp" />
</definition>
这是说一个模块下有多个功能点,每个功能点下的左侧菜单是相同的,因此leftBody就是这个左侧菜单,变化的只是rightBody右侧部分而已。下面还有详解。
/layout/ mainLayout.jsp
-----------------------------------------------------------------
…
<html>
<head>
<title><tiles:getAsString name="title" /></title>
…
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="mainInit()" >
<table cellpadding="0" cellspacing="0" class="LogoTable" id="01" >
<tr valign="bottom">
<tiles:insert attribute="logo" />
<tiles:insert attribute="mainMenu" />
</tr>
<tr valign="top" >
<tiles:insert attribute="submenu" />
</tr>
</table>
<table class="MainTable" cellpadding="1" cellspacing="1">
<tr class="TrMain">
<td width="225" >
<tiles:insert attribute="leftBody" />
</td>
<td width="775">
<table>
<tiles:insert attribute="messages" />
</table>
<tiles:insert attribute="rightBody" />
</td>
</tr>
</table>
</body>
</html>
在web.xml里面配置tiles对应的taglib的配置如下:
web.xml
-----------------------------------------------------------------
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
在struts-config.xml里面配置tiles-defs.xml
Struts-config.xml
-----------------------------------------------------------------
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/plugin/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-parser-validate"
value="true" />
</plug-in>
相关阅读 更多 +