`

20100623tiles随笔

阅读更多
  看了下系统框架展示使用的框架tiles,以前也没有深入了解过,开发中总是使用,没想过它的好处。今天抽了点时间看了下,特说明心得:
   Tiles 模板是一个一般不包含任何实际内容的布局。它包含一些占位符属性使得页面 URI 和字符串可以在将来被插入。
   使用tiles首先要做strust配置文件里引入,
<plug-in className="org.apache.struts.tiles.TilesPlugin">
        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml/>
        <set-property property="definitions-parser-validate" value="true"/>
  </plug-in>
2、配置tile使用的模版
  <definition name="template.default2"
path="/template/model_no_table.jsp">
<put name="selfscript" value="/indi2exe/common/selfscript.jsp" /> <!-- 默认值 可重载 -->
<put name="title"
value="财政一体化管理信息系统(IFMIS;"
direct="true" />
<put name="mainmenu" value="/template/mainmenu.do" />
<put name="edittree" value="/template/treemenu.do" />
<put name="navigation" value="/template/navigation.do" />
<put name="main" value="/common/_blank.html" />
<put name="showhelp" value="/common/_blank.html" />
</definition>
对于模版页面要按布局进行配置:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<jsp:directive.page import="java.util.Map;"/>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 6.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">


<link rel="stylesheet" type="text/css" href="<%=basePath%>/style/<%=gov.mof.fasp.ifmis.common.Globals.IFMIS_SKIN%>_style.css" />
<link rel="stylesheet" id="ifmisfontstyle" type="text/css" href="<%=basePath%>/style/<%=styleName %>" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>/style/<%=gov.mof.fasp.ifmis.common.Globals.IFMIS_LOGO%>_logo.css"/>
<link type="text/css" rel="stylesheet" href="<%=basePath%>/style/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>/style/calendar.css"/>
<script type="text/javascript" src="<%=basePath%>/js/prototype.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/choose.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/tabpage.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/changescroll.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/calendar.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/formatNumber.js"></script>
<script type="text/vbscript" src="<%=basePath%>/js/decode_resource.vbs"></script>
<script type="text/javascript" src="<%=basePath%>/js/ua.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/ftiens4.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/datatable.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/export.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/tbajax.js"></script>
<script type='text/javascript' src='<%=basePath%>/js/zapatec.js'></script>
<script type='text/javascript' src='<%=basePath%>/js/tree.js'></script>
<script type="text/javascript" src="<%=basePath%>/js/template.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/overlib/overlibmws.js" type=text/javascript></SCRIPT>
<script type="text/javascript" src="<%=basePath%>/js/overlib/overlibmws_filter.js" type=text/javascript></SCRIPT>
<script type="text/javascript" src="<%=basePath%>/js/overlib/overlibmws_shadow.js" type=text/javascript></SCRIPT>
<script type="text/javascript" src="<%=basePath%>/js/jquery-1[1].3.1.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/rightButton.js"></script>
<tiles:insert attribute="selfscript"/>


<script type="text/javascript">
var linkvchtypeid = '<%=request.getAttribute("linkvchtypeid")%>';
var ROOT_PATH = '<%=basePath%>';
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g,"");
}
<%
String intranetConfig ="";
if(session.getAttribute("intranetConfig")!="" && session.getAttribute("intranetConfig")!=null){
intranetConfig = session.getAttribute("intranetConfig").toString();
}

%>


function setFont(fontsize){
  if(fontsize=="l"){
    document.getElementById('ifmisfontstyle').href = '<%=basePath%>/style/stylefontL.css';
      setFontSession("stylefontL.css");
    }else if(fontsize=="m"){
      document.getElementById('ifmisfontstyle').href = '<%=basePath%>/style/stylefontM.css';
      setFontSession("stylefontM.css");
    }else{
      document.getElementById('ifmisfontstyle').href = '<%=basePath%>/style/stylefontS.css';
      setFontSession("stylefontS.css");
    }
    setFontCookie(fontsize);
}

</script>


<title>
    <tiles:insert attribute="title" />
</title>


<%
  
  String showAcctsystype = null;
 
  Map hpacctsystype = (Map)session.getAttribute("hpacctsystype");
  Object acctsystypeid = session.getAttribute("acctsystype");
  if(hpacctsystype != null && acctsystypeid != null){  
  showAcctsystype = (String)hpacctsystype.get(acctsystypeid.toString()) ;
  }
  if(showAcctsystype == null){
  showAcctsystype = "";
  }
  String hsagnecy = null;
  if(session.getAttribute("hsagencyname") != null){
  hsagnecy =  "/"+session.getAttribute("hsagencycode").toString()+"-"+session.getAttribute("hsagencyname").toString();
  }
 
  String isbudget = "";
  if(session.getAttribute("isbudget") != null){
  isbudget =  session.getAttribute("isbudget").toString();
  }
  if (showAcctsystype!=null && showAcctsystype!="" && isbudget.equals("2") && hsagnecy != null ){
  showAcctsystype += hsagnecy;
  }
  String currentuseragencyname = "";
if(session.getAttribute("currentuseragency")!=null){
java.util.HashMap currentuseragency = (java.util.HashMap)session.getAttribute("currentuseragency");
currentuseragencyname = currentuseragency.get("name").toString();
}

//单位类型
String agencyType = "";
if(session.getAttribute("currentagencytype")!=null&&session.getAttribute("currentagencytype")!=""){
agencyType = (String)session.getAttribute("currentagencytype");
}


%>
</head>
<body >
<div id="tree_inner" oncontextmenu="return false;"></div>
<div id="window_top" >
<div id="top" >
  <div id="logo">
    <table  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <th rowspan="2" nowrap="nowrap"></th>
        <td nowrap="nowrap">
<%--        <div><a title="显示版本信息" href="<%=basePath%>/version/index.html"><img src="../images/actions/version.gif" width="16" height="16" border="0"/> 版本</a></div>--%>
        <div><a title="退出" href="<%=basePath%>/logout.do"><img src="<%=basePath%>/images/actions/exit.gif" width="16" height="16" border="0"/> 退出 </a></div><div class="w_gang"></div>
          <div><a title="返回首页" href="<%=basePath%>/common/index.do"><img src="<%=basePath%>/images/actions/house.gif" width="16" height="16" /> 首页</a></div><div class="w_gang"></div>
      <div><img src="<%=basePath%>/images/actions/font_size.gif" width="16" height="16" border="0" title="字号" /><a href="#" onclick="setFont('l')">大</a><a href="#" onclick="setFont('m')"> 中</a><a href="#" onclick="setFont('s')"> 小</a></div><div class="w_gang"></div>
<%
     //启用ca 后不在一体化系统中修改密码 20100107
     String isportalca = "fasle" ;
if (session.getAttribute("isportalca")!=null ) isportalca =  (String)session.getAttribute("isportalca");
             if(isportalca.equalsIgnoreCase("false")) {%>
          <div><a title="修改密码" href="<%=basePath%>/portal/login/mod_password.jsp" target="_blank"><img src="<%=basePath%>/images/actions/mod_pwd.gif" width="16" height="16" border="0"/> 修改密码</a></div><div class="w_gang"></div>
<% } %>

         <% if(intranetConfig!=null&&intranetConfig!=""){%>
          <div><a title="进入内网" href="<%=intranetConfig%>"><img src="<%=basePath%>/images/actions/go_innerNet.gif" width="16" height="16" /> 内网</a></div><div class="w_gang"></div>  
          <%} %>   
         <div class="w_head"></div>
        <td width="6" nowrap="nowrap" class="w_right">&nbsp;</td>
      </tr>
      <tr>
        <td nowrap="nowrap" class="welcomeA">
        <% if(agencyType!=null&&agencyType!=""){%>
        <c:out value="${sessionScope.currentagencytype}"/>:<c:out value="${sessionScope.currentuseragency.name}"/>
        <%}else if(currentuseragencyname!=null && currentuseragencyname!=""){%>
         单位:<c:out value="${sessionScope.currentuseragency.name}"/>
        <%} %>      
        <%if (showAcctsystype!=null && showAcctsystype!=""){%>
         账套:<%=showAcctsystype%>
        <% } %>
         用户:<c:out value="${sessionScope.currentuser.name}"/>
         <% if(agencyType!=null&&agencyType!=""){%>日期:<%}else{%>系统日期:<%}%>        
         <span id=cdate>
         <% java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
        out.println(formatter.format(new java.util.Date()));
         %></span></td>
        <td nowrap="nowrap">&nbsp;</td>
      </tr>  
    </table>
  </div>
  <div id="menu">
     <tiles:insert attribute="mainmenu"/>
  </div>
</div>
</div>
<div id="hidden_top" align="center" ><span id="hiddenTopBar" title="隐藏上部" onClick="doHiddenTop(this)"></span></div>
<div style="position:relative;background-color:#CCCCCC; overflow:hidden;height:expression(this.offsetParent.offsetHeight-window_top.offsetHeight-hidden_top.offsetHeight-10);">
    <div id="left_tree" style="display:block; height:expression(this.offsetParent.offsetHeight-25); overflow-y:scroll">
       <tiles:insert attribute="edittree"/></div>
    <div id="switchBar" style="display:block; height:expression(this.offsetParent.style.height); overflow:hidden">
        <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
       <tr>
        <td align="center"><span id="hiddenLeftBar" title="隐藏左侧树" onClick="doHiddenLeft(this)"></span></td>
       </tr>
       </table>
    </div>
    <tiles:insert attribute="selfscript"/>
    <div id="main" style="display:block; height:expression(this.offsetParent.style.height);">   
       <tiles:insert attribute="navigation"/>
       <div id ="context">
       <tiles:insert attribute="main"/>
       <tiles:insert attribute="showhelp"/>
       </div>
    </div>  
</div>
</body>
</html>
在模版文件中tiles使用的语法为
<tiles:insert attribute="****"/>
attribute的属性为模版站位符,可以动态放置不同的页面。



   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics