1:定义tid文件

<tag><name>select</name><tag-class>com.zhoujun.jsp.day02.SelectTag</tag-class><body-content>JSP</body-content><attribute><name>name</name><required>false</required><rtexprvalue>false</rtexprvalue></attribute> <attribute><name>items</name><required>true</required><rtexprvalue>true</rtexprvalue></attribute> <attribute><name>valueKey</name><required>true</required><rtexprvalue>false</rtexprvalue></attribute> <attribute><name>kextKey</name><required>true</required><rtexprvalue>false</rtexprvalue></attribute> <attribute><name>cssStyle</name><required>false</required><rtexprvalue>false</rtexprvalue></attribute> <attribute><name>headKey</name><required>false</required><rtexprvalue>false</rtexprvalue></attribute> <attribute><name>headVale</name><required>false</required><rtexprvalue>false</rtexprvalue></attribute> <attribute><name>sov</name><required>false</required><rtexprvalue>false</rtexprvalue></attribute> </tag>

tag类

package com.zhoujun.jsp.day02;import java.lang.reflect.InvocationTargetException;
import java.util.List;import javax.management.RuntimeErrorException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;import org.apache.commons.beanutils.PropertyUtils;public class SelectTag extends BodyTagSupport {private List<Object> items;private String name;private String valueKey;//保存option中value的keyprivate String kextKey;//保存option中text的keyprivate String cssStyle;private String headKey;private String headVale;private String sov;public String getCssStyle() {return cssStyle;}public void setCssStyle(String cssStyle) {this.cssStyle = cssStyle;}public String getHeadKey() {return headKey;}public void setHeadKey(String headKey) {this.headKey = headKey;}public String getHeadVale() {return headVale;}public void setHeadVale(String headVale) {this.headVale = headVale;}public String getSov() {return sov;}public void setSov(String sov) {this.sov = sov;}public SelectTag() {super();// TODO Auto-generated constructor stub}public List<Object> getItems() {return items;}public void setItems(List<Object> items) {this.items = items;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getValueKey() {return valueKey;}public void setValueKey(String valueKey) {this.valueKey = valueKey;}public String getKextKey() {return kextKey;}public void setKextKey(String kextKey) {this.kextKey = kextKey;}@Overridepublic int doStartTag() throws JspException {JspWriter out = pageContext.getOut();try {String html = toHtml();out.println(html);} catch (Exception e) {throw new RuntimeException();}return super.doStartTag();}private String toHtml() throws Exception  {StringBuffer sb=new StringBuffer();//<select name="" style="">sb.append("<select name='"+name+"' ");sb.append("style='"+cssStyle+"' ");sb.append(">");//<option value=""></option>if (null!=items &&0!=items.size()) {if(null!=headKey && !"".equals(headKey.trim())){sb.append("<option value='"+headKey+"'>"+headVale+"</option>");}Object value=null;Object text=null;for (Object object:items) {//反射value=PropertyUtils.getProperty(object, valueKey);text=PropertyUtils.getProperty(object, kextKey);if(value.toString().equals(sov.trim())) {sb.append("<option selected value='"+value+"'>"+value+"</option>");}else {sb.append("<option value='"+text+"'>"+value+"</option>");}}      }sb.append("</select>");return sb.toString();}}

dao类

package com.zhoujun.dao;import java.util.ArrayList;
import java.util.List;import com.zhoujun.entity.Dept;public class DeptDao {public List<Dept> list(){//数据访问库List<Dept> list =new ArrayList<Dept>();list.add(new Dept(1,"王者职业"));list.add(new Dept(2,"吃鸡职业"));list.add(new Dept(3,"手游职业"));list.add(new Dept(4,"端游职业"));return list;}  }

实体类

package com.zhoujun.entity;import java.io.Serializable;public class Dept implements Serializable{private static final long serialVersionUID = 7931897061787572973L;private  Integer deptId;private String deptName;public Integer getDeptId() {return deptId;}public void setDeptId(Integer deptId) {this.deptId = deptId;}public String getDeptName() {return deptName;}public void setDeptName(String deptName) {this.deptName = deptName;}public Dept(Integer deptId, String deptName) {super();this.deptId = deptId;this.deptName = deptName;}public Dept() {}@Overridepublic String toString() {return "Dept [deptId=" + deptId + ", deptName=" + deptName + "]";}}

最后在jsp页面输出

<h2>自定义标签select标签----------</h2>
<z:select items="${deptList }" kextKey="deptId" valueKey="deptName" cssStyle="width:150px"headKey="-1" headVale="-------选择-----" sov="2">
</z:select>

输出结果

总结 :

自定义select标签相关推荐

  1. JSP自定义select标签中取值

    JSP自定义select标签的取值 select取值是通过name属性获取. 自定义标签的流程: 1.继承JSP标签的标签类TagSupport,SimpleTagSupport等,重写dostart ...

  2. 实现自定义select标签

      我们经常会遇到这种场景:     假设项目中有一个分类对象,类似数据字典,一个code对应一个name.这个在页面作为一个过滤条件:选择分类.一般做法是在jsp页面直接写select标签,用opt ...

  3. springboot+thymeleaf自定义select标签

    效果 <sys:dict type="DISEASES_OPTION" name="option_code" class="" /&g ...

  4. html select 修改默认箭头样式,自定义select标签箭头样式

    select::-ms-expand{ display: none; }//ie样式清除 select{ appearance:none; -moz-appearance:none; -webkit- ...

  5. html下拉选择框箭头改为年,CSS自定义select下拉选择框的样式(不用其他标签模拟)...

    今天群里有人问到怎么自定义select下拉选择框的样式,于是群里就展开了激烈的讨论,刚开始一直就是考虑怎样使用纯CSS实现,把浏览器默认的样式覆盖掉,但最后均因兼容问题处理不好而失败告终,最后的解决方 ...

  6. 自定义html下拉选择框,CSS自定义select下拉选择框的样式(不用其他标签模拟)

    今天群里有人问到怎么自定义select下拉选择框的样式,于是群里就展开了激烈的讨论,刚开始一直就是考虑怎样使用纯CSS实现,把浏览器默认的样式覆盖掉,但最后均因兼容问题处理不好而失败告终,最后的解决方 ...

  7. 基于Bootstrap里面的Button dropdown打造自定义select

    最近工作非常的忙,在对一个系统进行改版.项目后台是MVC1.0开发的,但是前端部分已经改过几个版本,而已之前的设计师很强大,又做设计又做前端开发.而已很时尚和前沿,使用了一直都很热门的Bootstra ...

  8. FineReport中如何用JavaScript自定义地图标签

    2019独角兽企业重金招聘Python工程师标准>>> 在日常使用地图过程中,通常会遇到地图标签,提示点等显示不满足我们的需求,需要进行JavaScript代码编写. 例如:在使用地 ...

  9. php嵌套模板,thinkphp3.1自定义模板标签嵌套实现

    thinkphp3.1自定义模板标签嵌套实现 之前做的自定义标签,属性里面读取不到上层标签的值,然后找了很多文档发现没有能解决的,然后就自己研究了一下,搞出来了,下面是方法,绝对能用,不能用我吃了它. ...

最新文章

  1. 生成有关 SQL Server 2005 Analysis Services 多维数据集数据源的本地化报表
  2. 使用非侵入性脑机接口和计算机视觉引导对机器人手臂进行共享控制
  3. C++中的值传递、指针传递、引用传递
  4. kali 安装volatility_kali对Windows内存在线取证
  5. IIS负载均衡-Application Request Route详解第四篇:使用ARR实现三层部署架构
  6. 只读副本和Spring Data第4部分:配置只读存储库
  7. 前端学习(1840):前端面试题之小程序入门
  8. 报错:OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialized.
  9. 《Python编程从入门到实践》第10章文件和异常动手试一试答案(附代码)
  10. BOSS直聘发起“逆行者先行”招聘专场:优先录取抗疫志愿者
  11. LinkedList和ArrayList异同
  12. jhipster详解
  13. HTTP接口测试工具Postman
  14. tomcat 部署指南
  15. python RE表达式规则剩余规则
  16. 基于Mathemtica绘制一元酸滴定碱的滴定曲线(含V--PH曲线方程的推导)
  17. 华米Zepp小程序开发入门
  18. Unity3D 快捷键技巧
  19. flowable-6.7(一)从工作流与BPMN到flowable
  20. 海康威视启用码流加密_如何在Windows 10上启用全盘加密

热门文章

  1. 企业网络中的防火墙旁挂实例
  2. JOOQ 踩坑和评价
  3. python36.dll 0xc000005_使用python运行时出现0xc000005错误
  4. TMC5160 静音驱动器
  5. 电机控制器,FPGA 硬件电流环 基于FPGA的永磁同步伺服控制系统的设计
  6. centos7查看udp端口_linux7-netstat命令查看开放了那些端口
  7. Amazon亚马逊常见的几种label
  8. 概率论知识回顾(二十):随机变量序列收敛性
  9. BLDC控制方案简介
  10. 深圳软件测试培训:简述关系型数据库和非关系型数据库