package org.topteam.ui.model;
import com.alibaba.fastjson.JSON;
import org.topteam.ui.easyui.EventListenerTag;
import org.topteam.ui.easyui.EventTag;
import org.topteam.ui.easyui.FacetTag;
import org.topteam.ui.easyui.TagRender;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 一次JSP页面EasyUI控件解析的上下文。
* 从解析Body开始到Body结束,所有控件的一些属性会被暂存
* 在解析body结束的时候,写出所有控件前端渲染的方法。
* Created by 枫 on 2014/8/7.
*/
public class RenderContext {
public static final String REQUEST_TAG_NAME = "_jeasyui_rendercontext__";
public static final String JEASYUI_TAG_NAME = "__jeasyui__";
private final Map<String, TagRender> tags = new LinkedHashMap<String, TagRender>();
private final List<EventListenerTag> eventListeners = new ArrayList<EventListenerTag>();
private final List<EventTag> events = new ArrayList<EventTag>();
private final List<FacetTag> facets = new ArrayList<FacetTag>();
private AtomicInteger atomic = new AtomicInteger(1000);
private StringBuilder scriptBeforeWriter = new StringBuilder();
private String userAgent;
public RenderContext(HttpServletRequest request) {
this.userAgent = request.getHeader("user-agent");
}
private boolean isIE(){
return userAgent.contains("MSIE");
}
private boolean isIE8(){
return userAgent.contains("MSIE 8.0");
}
private boolean isIE9(){
return userAgent.contains("MSIE 9.0");
}
/**
* 将当前jsp页面解析过程中的所有控件放入上下文中 <br />
* {@link org.topteam.ui.easyui.TagRender}实现了{@linkplain java.lang.Cloneable}接口,由于{@link javax.servlet.jsp.tagext.TagSupport} 本身没有实现Clone,所以需要注意parent Tag无法clone。
*
* @param tag
* @throws JspTagException
*/
public void putTag(TagRender tag) throws JspTagException {
if (tag != null && tag.getId() != null) {
if (tags.containsKey(tag.getId())) {
// 由于涉及到控件的事件绑定,所以我们强制控件的ID不可以重复
throw new JspTagException("存在重复的ID:" + tag.getId());
}
tags.put(tag.getId(), tag);
}
}
/**
* 通过控件id获取{@linkplain org.topteam.ui.easyui.TagRender}
*
* @param id
* @return TagRender
*/
public TagRender getTag(String id) {
return tags.get(id);
}
/**
* 添加EventListenerTag到eventListeners
*
* @param eventListenerTag
*/
public void putEventListener(EventListenerTag eventListenerTag) {
eventListeners.add(eventListenerTag);
}
/**
* 添加EventTag到events
*
* @param eventTag
*/
public void putEvent(EventTag eventTag) {
events.add(eventTag);
}
/**
* 输出所有控件初始化的js代码
*
* @param out
* @param var
* @throws IOException
*/
public void write(JspWriter out, String var) throws IOException {
//输出Facet的Html代码
for (FacetTag facet : facets) {
if (facet.getBody() != null) {
out.write(facet.getBody());
out.write("\n");
}
}
ScriptWriter sw = new ScriptWriter();
if(isIE8() || isIE9()){
sw.ready();
}
sw.write(getScriptBeforeWriter().toString());
// loop all tags
for (Iterator<String> iterator = tags.keySet().iterator(); iterator.hasNext(); ) {
String tagId = iterator.next();
TagRender tag = tags.get(tagId);
if (tag.getEasyuiTag() != null) {
// get one tag's event listeners
List<EventListenerTag> listeners = getEventListeners(tag);
// get one tag's event actions
List<EventTag> events = getEvents(tag);
// get one tag's facet
List<FacetTag> facetTags = getFacets(tag);
String tagScript = getTagScript(tag, listeners, events, facetTags);
sw.write(tagScript);
} else {
List<EventListenerTag> listeners = getEventListeners(tag);
// get one tag's event actions
List<EventTag> events = getEvents(tag);
String tagScript = getJQueryScript(tag, listeners, events);
sw.write(tagScript);
}
String afterScript = tag.doAfterTagRenderScript();
sw.write(afterScript == null ? "" : afterScript);
sw.write("\n");
}
if (tags != null) {
Map<String, String> tagsJs = new HashMap<String, String>();
for (Iterator<String> iterator = tags.keySet().iterator(); iterator.hasNext(); ) {
String tagId = iterator.next();
if (tags.get(tagId).getEasyuiTag() != null) {
tagsJs.put(tagId, tags.get(tagId).getEasyuiTag());
}
}
sw.write("var " + var + " = jeasyui(" + JSON.toJSONString(tagsJs) + ");");
}
out.write(sw.toString());
}
private List<FacetTag> getFacets(TagRender tag) {
List<FacetTag> facetTags = new ArrayList<FacetTag>();
for (FacetTag facet : facets) {
if (facet.getParentId() != null && facet.getParentId().equals(tag.getId())) {
facetTags.add(facet);
}
}
return facetTags;
}
/**
* 获取tag的渲染构建js代码,同时注册相关事件监听
*
* @param tag
* @param listeners
* @param events
* @param facetTags
* @return
*/
private String getTagScript(TagRender tag, List<EventListenerTag> listeners, List<EventTag> events, List<FacetTag> facetTags) {
StringBuilder sb = new StringBuilder();
sb.append("$('#").append(tag.getId()).append("').").append(tag.getEasyuiTag()).append("(");
Map<String, String> eventBindString = buildEasyEventScript(listeners, events);
if (!tag.isJqueryEventBind()) {
if (eventBindString.size() > 0 || facetTags.size() > 0) {
sb.append("{\n");
}
for (Iterator<String> iterator = eventBindString.keySet().iterator(); iterator.hasNext(); ) {
String event = iterator.next();
String binds = eventBindString.get(event);
sb.append(event).append(":").append("function(){").append("\n");
sb.append("var args = arguments;\n");
sb.append(binds);
sb.append("}");
if (iterator.hasNext() || facetTags.size() > 0) {
sb.append(",");
}
}
for (Iterator<FacetTag> iterator = facetTags.iterator(); iterator.hasNext(); ) {
FacetTag facet = iterator.next();
sb.append(facet.getName()).append(":").append("'#").append(facet.getId()).append("'");
if (iterator.hasNext()) {
sb.append(",");
}
}
if (eventBindString.size() > 0 || facetTags.size() > 0) {
sb.append("\n}");
}
}
sb.append(");");
if (tag.isJqueryEventBind()) {
for (Iterator<String> iterator = eventBindString.keySet().iterator(); iterator.hasNext(); ) {
String event = iterator.next();
String binds = eventBindString.get(event);
sb.append("$('#").append(tag.getId()).append("').bind(");
sb.append("'").append(event).append("',
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该项目为基于Java的JSP EasyUI封装设计源码,共包含1284个文件,其中CSS文件469个,PNG图片文件375个,Java源文件178个,JavaScript文件159个,JSP文件37个,GIF图片文件33个,XML文件3个,TLD文件3个,JSON文件3个,SWF文件3个。该封装简化了JSP中使用EasyUI的过程,适用于构建基于JSP的界面应用。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的JSP EasyUI封装设计源码 (1285个子文件)
bootstrap.css 134KB
bootstrap.min.css 111KB
easyui.css 55KB
easyui.css 54KB
easyui.css 54KB
easyui.css 54KB
easyui.css 51KB
easyui.css 51KB
easyui.css 51KB
easyui.css 51KB
easyui.css 51KB
easyui.css 51KB
easyui.css 50KB
easyui.css 50KB
easyui.css 50KB
easyui.css 47KB
easyui.css 47KB
font-awesome-ie7.min.css 45KB
font-awesome.css 26KB
font-awesome.min.css 21KB
bootstrap-theme.css 21KB
docs.min.css 21KB
bootstrap-theme.min.css 19KB
tabs.css 9KB
tabs.css 9KB
tabs.css 9KB
tabs.css 9KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 7KB
shCore.css 7KB
mobile.css 7KB
tabs.css 6KB
tabs.css 6KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
linkbutton.css 4KB
color.css 4KB
color.css 4KB
color.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
calendar.css 4KB
shThemeEclipse.css 4KB
tree.css 3KB
shThemeFadeToGrey.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
shThemeRDark.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
共 1285 条
- 1
- 2
- 3
- 4
- 5
- 6
- 13
资源评论
csbysj2020
- 粉丝: 2752
- 资源: 5562
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (18956428)STM32F103C8T6 小系统原理图 PCB
- (175828796)python全国疫情数据爬虫可视化分析系统(django)源码数据库演示.zip
- 记账本项目市场需求文档(MRD)
- (31687028)PID控制器matlab仿真.zip
- 基于SpringBoot的“在线答疑系统”的设计与实现(源码+数据库+文档+PPT).zip
- (11828838)进销存系统源码
- 记账本项目三大模块原型图
- fed54987-3a28-4a7a-9c89-52d3ac6bc048.vsidx
- (177367038)QT实现教务管理系统.zip
- (178041422)基于springboot网上书城系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功