1. 引入

    1. <%@ taglib prefix="sys" tagdir="/WEB-INF/tags/sys" %>
  1.  

  1. 这里注意/WEB-INF/tags/sys这里是一个目录,目录下有很多tag文件如下,调用sys:xxx,就会在当前目录下找xxx.tag的文件,必须有对应xxx.tag的文件与之对应

    1. <%@ tag language="java" pageEncoding="UTF-8"%>
    1. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    1. <%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
    1. <%@ attribute name="typeCode" type="java.lang.String" required="true" description="字典code"%>
    1. <%@ attribute name="defaultValue" type="java.lang.String" description="默认选中"%>
    1. <%@ attribute name="style" type="java.lang.String" description="默认选中"%>
    1. <%@ attribute name="cls" type="java.lang.String" description="默认选中"%>
    1. <%@ attribute name="name" type="java.lang.String" description="默认选中"%>
    1. <select style="${style}" class="${cls}" name="${name}" id="${name}" >
    1. <option value="" >请选择... </option>
    1. <c:if test="${not empty typeCode}">
    1. <c:forEach items="${fns:getDictList(typeCode)}" var='dict'>
    1. <option value='${dict.VALUE}' ${defaultValue==dict.VALUE?'selected':''}>${dict.TEXT}</option>
    1. </c:forEach>
    1. </c:if>
    1. </select>
  1.  
  2. attribute的属性介绍如下: 
    1. name :这个attribute的名称. 
    2. required : true/false, 是否必须的. 
    3. rtexprvalue : true/false, 这个attribute可否使用EL表达式, 否则为纯文本. 
    4. type : 设定这个attribute的类型, jsp容器会把结果自动转换成这个类.

  1. 如此,jsp名就是标签名,例如这个jsp select.jsp,那么它的用法就是
  1. <sys:select cls="formselect" name="MODULE_TYPE" typeCode="HOME_MODULE_TYPE" defaultValue="${record.MODULE_TYPE }" />

附上一个实际例子

treeselect.tag

    1. <%@ tag language="java" pageEncoding="UTF-8"%>
    1. <%@ include file="/WEB-INF/views/include/taglib.jsp"%>
    1. <%@ attribute name="id" type="java.lang.String" required="true" description="编号"%>
    1. <%@ attribute name="name" type="java.lang.String" required="true" description="隐藏域名称(ID)"%>
    1. <%@ attribute name="value" type="java.lang.String" required="true" description="隐藏域值(ID)"%>
    1. <%@ attribute name="labelName" type="java.lang.String" required="true" description="输入框名称(Name)"%>
    1. <%@ attribute name="labelValue" type="java.lang.String" required="true" description="输入框值(Name)"%>
    1. <%@ attribute name="title" type="java.lang.String" required="true" description="选择框标题"%>
    1. <%@ attribute name="url" type="java.lang.String" required="true" description="树结构数据地址"%>
    1. <%@ attribute name="checked" type="java.lang.Boolean" required="false" description="是否显示复选框,如果不需要返回父节点,请设置notAllowSelectParent为true"%>
    1. <%@ attribute name="extId" type="java.lang.String" required="false" description="排除掉的编号(不能选择的编号)"%>
    1. <%@ attribute name="isAll" type="java.lang.Boolean" required="false" description="是否列出全部数据,设置true则不进行数据权限过滤(目前仅对Office有效)"%>
    1. <%@ attribute name="notAllowSelectRoot" type="java.lang.Boolean" required="false" description="不允许选择根节点"%>
    1. <%@ attribute name="notAllowSelectParent" type="java.lang.Boolean" required="false" description="不允许选择父节点"%>
    1. <%@ attribute name="module" type="java.lang.String" required="false" description="过滤栏目模型(只显示指定模型,仅针对CMS的Category树)"%>
    1. <%@ attribute name="selectScopeModule" type="java.lang.Boolean" required="false" description="选择范围内的模型(控制不能选择公共模型,不能选择本栏目外的模型)(仅针对CMS的Category树)"%>
    1. <%@ attribute name="allowClear" type="java.lang.Boolean" required="false" description="是否允许清除"%>
    1. <%@ attribute name="allowInput" type="java.lang.Boolean" required="false" description="文本框可填写"%>
    1. <%@ attribute name="cssClass" type="java.lang.String" required="false" description="css样式"%>
    1. <%@ attribute name="cssStyle" type="java.lang.String" required="false" description="css样式"%>
    1. <%@ attribute name="smallBtn" type="java.lang.Boolean" required="false" description="缩小按钮显示"%>
    1. <%@ attribute name="hideBtn" type="java.lang.Boolean" required="false" description="是否显示按钮"%>
    1. <%@ attribute name="disabled" type="java.lang.String" required="false" description="是否限制选择,如果限制,设置为disabled"%>
    1. <%@ attribute name="dataMsgRequired" type="java.lang.String" required="false" description=""%>
    1. <div class="input-append">
    1. <input id="${id}Id" name="${name}" class="${cssClass}" type="hidden" value="${value}"/>
    1. <input id="${id}Name" name="${labelName}" ${allowInput?'':'readonly="readonly"'} type="text" value="${labelValue}" data-msg-required="${dataMsgRequired}"
    1. class="${cssClass}" style="${cssStyle}"/><a id="${id}Button" href="javascript:" class="btn ${disabled} ${hideBtn ? 'hide' : ''}" style="${smallBtn?'padding:4px 2px;':''}">&nbsp;<i class="icon-search"></i>&nbsp;</a>&nbsp;&nbsp;
    1. </div>
    1. <script type="text/javascript">
    1. $("#${id}Button, #${id}Name").click(function(){
    1. // 是否限制选择,如果限制,设置为disabled
    1. if ($("#${id}Button").hasClass("disabled")){
    1. return true;
    1. }
    1. // 正常打开
    1. top.$.jBox.open("iframe:${ctx}/tag/treeselect?url="+encodeURIComponent("${url}")+"&module=${module}&checked=${checked}&extId=${extId}&isAll=${isAll}", "选择${title}", 300, 420, {
    1. ajaxData:{selectIds: $("#${id}Id").val()},buttons:{"确定":"ok", ${allowClear?"\"清除\":\"clear\", ":""}"关闭":true}, submit:function(v, h, f){
    1. if (v=="ok"){
    1. var tree = h.find("iframe")[0].contentWindow.tree;//h.find("iframe").contents();
    1. var ids = [], names = [], nodes = [];
    1. if ("${checked}" == "true"){
    1. nodes = tree.getCheckedNodes(true);
    1. }else{
    1. nodes = tree.getSelectedNodes();
    1. }
    1. for(var i=0; i<nodes.length; i++) {//<c:if test="${checked && notAllowSelectParent}">
    1. if (nodes[i].isParent){
    1. continue; // 如果为复选框选择,则过滤掉父节点
    1. }//</c:if><c:if test="${notAllowSelectRoot}">
    1. if (nodes[i].level == 0){
    1. top.$.jBox.tip("不能选择根节点("+nodes[i].name+")请重新选择。");
    1. return false;
    1. }//</c:if><c:if test="${notAllowSelectParent}">
    1. if (nodes[i].isParent){
    1. top.$.jBox.tip("不能选择父节点("+nodes[i].name+")请重新选择。");
    1. return false;
    1. }//</c:if><c:if test="${not empty module && selectScopeModule}">
    1. if (nodes[i].module == ""){
    1. top.$.jBox.tip("不能选择公共模型("+nodes[i].name+")请重新选择。");
    1. return false;
    1. }else if (nodes[i].module != "${module}"){
    1. top.$.jBox.tip("不能选择当前栏目以外的栏目模型,请重新选择。");
    1. return false;
    1. }//</c:if>
    1. ids.push(nodes[i].id);
    1. names.push(nodes[i].name);//<c:if test="${!checked}">
    1. break; // 如果为非复选框选择,则返回第一个选择 </c:if>
    1. }
    1. $("#${id}Id").val(ids.join(",").replace(/u_/ig,""));
    1. $("#${id}Name").val(names.join(","));
    1. }//<c:if test="${allowClear}">
    1. else if (v=="clear"){
    1. $("#${id}Id").val("");
    1. $("#${id}Name").val("");
    1. }//</c:if>
    1. if(typeof ${id}TreeselectCallBack == 'function'){
    1. ${id}TreeselectCallBack(v, h, f);
    1. }
    1. }, loaded:function(h){
    1. $(".jbox-content", top.document).css("overflow-y","hidden");
    1. }
    1. });
    1. });
    1. </script>


jsp tag 直接文件实现的更多相关文章

  1. JSP TAG

    Jsp tag 能够灵活的将公共JSP代码模块化,类似<jsp:include page="./include.jsp"></jsp:include>等等. ...

  2. Servlet和JSP之标签文件学习

    在上一篇文章中介绍了自定义标签的用法,接下来介绍标签文件的用法啦. tag file指令 tag file简介 用tag file的方式,无需编写标签处理类和标签库描述文件,也可以自定义标签.tag ...

  3. Liferay JSP Tag Libraries介绍

    Liferay自带了很多标签库,这极大地提高了开发Liferay项目的效率. 下面让我们一起来探索吧. 什么是标签库? 什么是JSP标签? 什么是JSTL? 标签库由下面这几部分组成: Tag Lib ...

  4. jsp读取properties文件

    jsp读取properties文件 jsp中读取properties文件,并把值设到js变量中: mpi.properties文件内容: MerchantID=00000820 CustomerEMa ...

  5. Eclipse中jsp、js文件编辑时,卡死现象解决汇总

    使用Eclipse编辑jsp.js文件时,经常出现卡死现象,在网上百度了N次,经过N次优化调整后,卡死现象逐步好转,具体那个方法起到作用,不太好讲.将所有用过的方法罗列如下: 1.取消验证 windo ...

  6. Java使用JSP Tag Files & JSP EL Functions打造你自己的页面模板

    1. 简单说明:在JSP 2.0后, 你不再需要大刀阔斧地定义一堆TagSupport或BodyTagSupport, 使用JSP Tag Files技术可以实现功能强大的页面模板技术. 在这里抛砖引 ...

  7. Eclipse编辑jsp、js文件时,经常出现卡死现象解决汇总

    使用Eclipse编辑jsp.js文件时,经常出现卡死现象,在网上百度了N次,经过N次优化调整后,卡死现象逐步好转,具体那个方法起到作用,不太好讲.将所有用过的方法罗列如下: 1.取消验证 windo ...

  8. eclipse中web项目部署以后jsp的java文件找不到问题(Tomcat配置serverlocations)

    我的开发环境:eclipse kepler (4.3)+tomcat7.0.42. 在我想看eclipse中web项目jsp文件被tomcat转换成java以后的java源文件的位置,发现正常情况下的 ...

  9. JSP生成word文件

    1.jsp生成word文件,直接改动jsp格式: <%@ page contentType="application/vnd.ms-word;charset=GB2312"% ...

随机推荐

  1. [转]sa不能远程连接sql server 2008的解决办法

    本文转自:http://www.cnblogs.com/chendaoyin/archive/2012/08/25/2656900.html 方法: 开始->Microsoft SQL Serv ...

  2. iOS:对GCD中 同步、异步、并行、串行的见解

    1.GCD-同步执行多线程时          GCD中不管向什么类型的队列加同步任务,实际上都会加到当前线程中(一般为主线程). 2.GCD-异步执行多线程时          GCD中不管向什么类 ...

  3. 向PE文件植入后门代码技术讨论

    写在前面的话 这篇文章将介绍使用codecaves对PE文件植入后门代码.有几个很好的工具可以帮到你了.比如BackdoorFactory和Shelter将完成相同的工作,甚至绕过一些静态分析几个防病 ...

  4. 通过HTTP发包工具了解HTTP协议

    一.HTTP.pl功能简介 HTTP.pl perl编写的发包工具,简化版本curl,像curl致敬(唉,“致敬”都被于妈玩坏了).   该发包工具支持HEAD,GET,METHOD三种基本请求方法, ...

  5. material.setTexture("sampler",tex) assetbundle 下失效

    做镜面反射本来写很顺 在手机上测的时候 发现settexture这里绑不上 查好久 是assetbundle的缘故 因为动态加载的 obj用了mat01 我在反射脚本里动态修改mat01而不是拿 re ...

  6. Git的状态转换

             近期公司用Git来管理代码,用起来是要比svn爽一些.就是刚接触的时候比較痛苦,特别是那些状态(版本号的提交/合并/回退).差点把我搞晕了. 如今回过头来总结一下,就清楚多了.   ...

  7. VC在windows中打开文件夹并选中文件

    网上一位前辈高人的一段精髓代码让我眼前一亮…… ShellExecute(NULL, "open", "explorer.exe", "/select ...

  8. HTTP状态码具体解释

    HTTP状态码(HTTP Status Code)是用以表示网页serverHTTP响应状态的3位数字代码.它由 RFC 2616 规范定义的,并得到RFC 2518.RFC 2817.RFC 229 ...

  9. ffmpeg的新东东:AVFilter

    http://blog.csdn.net/niu_gao/article/details/7219641 利用ffmpeg做图像的pixel format转换你还在用libswscale吗?嘿嘿,过时 ...

  10. org.eclipse.e4.core.di.InjectionException:org.eclipse.swt.SWTException: Widget is disposed

    org.eclipse.e4.core.di.InjectionException:org.eclipse.swt.SWTException: Widget is disposed 开发环境为ecli ...