惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
爱范儿
爱范儿
月光博客
月光博客
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
T
Tailwind CSS Blog
美团技术团队
D
Docker
V
Visual Studio Blog
Martin Fowler
Martin Fowler
博客园 - 聂微东
The Cloudflare Blog

博客园 - 消失的风

富文本编辑器vue2-editor实现全屏功能 使用Mist部署Contract到Rinkeby以太坊网络 基于以太坊的Token开发步骤 技术顾问认知(一) Angularjs-项目搭建 Augularjs-起步 appfuse:Excel导出 基于JQuery实现的文本框自动填充功能 Appfuse:权限控制 Appfuse:记录操作日志 Appfuse:扩展自己的GenericManager Appfuse:第一张表维护 Appfuse:起步 JAVA实现图片裁剪 Mybatis基于注解的方式访问数据库 敏捷开发与jira之研发管理模式 敏捷开发与jira之阶段工作项概述 敏捷开发与jira之燃烧图 敏捷开发与jira之流程
Appfuse:添加自定义页面组件
消失的风 · 2015-07-17 · via 博客园 - 消失的风

我之前是做ASP.NET的,碰到被多个页面都使用的类似组件后,就想着采用ascx(用户自定义组件)来解决,那做Java我也想用这种方案。

我要做的效果如下:

实现方案:tag方式(自定义标签)

1. 首先定义自己的tag

 1 <%@ tag body-content="scriptless" pageEncoding="UTF-8"%>
 2 <%@ attribute name="table" required="true"%>
 3 <%@ attribute name="idfield" required="true"%>
 4 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
 5 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 6 <c:set var="base" value="${pageContext.request.contextPath}" />
 7 <c:set var="typeList" />
 8 <script src="<c:url value="/scripts/jquery/jquery.1.10.2.min.js" />"></script>
 9 <form method="post">
10     <div id="divRecomment">
11         <fmt:message key="recomment.title" />
12         &nbsp;&nbsp;
13         <select id="recommendAction" name="recommendAction">
14             <c:forEach items="${recommenttype}" var="t">
15                 <option value="${t.key}">${t.value}</option>
16             </c:forEach>
17         <select>
18         &nbsp;&nbsp; <input type="button" onclick="handleRecomment();"
19             value='<fmt:message key="recomment.submit"/>' class="btn btn-primary" />
20     </div>
21 </form>

recommend.tag

2. 使用自定义的标签

<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

<t:recommend table="" idfield=""></t:recommend>

3. recommenttype 的数据源:使用页面对应的Controller中的handleRequest

1 HashMap<String,String> recommentType = new HashMap<String,String>();
2         recommentType.put("1", "首页");  
3         recommentType.put("2", "其他");   
4         request.setAttribute(Constants.RECOMMENT_TYPE, recommentType);

handleRequest

附用到的样式

1 #divRecomment{
2     margin-left:12px;
3 }
4 #divRecomment select{
5     width:200px;
6     height:38px;
7     border:1px solid #cccccc;
8 }

main.css