Jfinal集成easyui标签-第一章基础配置

 第一步配置 JfinalConfig

 

		me.setMainRenderFactory(new BeetlRenderFactory());
		GroupTemplate groupTemplate = BeetlRenderFactory.groupTemplate;
		groupTemplate.registerTag("menu", MenuTag.class);
		groupTemplate.registerTag("table", DataGridTag.class);
		groupTemplate.registerTag("tr", DataGridColumnTag.class);
		groupTemplate.registerTag("opt", DataGridOptTag.class);

 第二步配置beetl.properties

#classpath 根路径 
RESOURCE.root= /WEB-INF/pages/
#是否检测文件变化
RESOURCE.autouCheck= true
#子父标签处理
TAG.htmltag= com.htmlps.core.tag.util.HTMLNestTagSupportWrapper

 第三步编写HTMLNestTagSupportWrapper

public class HTMLNestTagSupportWrapper extends HTMLTagSupportWrapper {

	@Override
	public void render() {
		HttpServletRequest request = (HttpServletRequest) this.ctx.getGlobal("request");
		TagNestContext tnc = (TagNestContext) request.getAttribute("tagContext");
		if (tnc == null) {
			tnc = new TagNestContext();
			
			tnc.setTags(this.args);
			request.setAttribute("tagContext", tnc);
			super.render();
			request.removeAttribute("tagContext");
		} else {
			TagNestContext child = new TagNestContext();
			child.setParent(tnc);
			child.setTags(this.args);
			tnc.getChildren().add(child);
			request.setAttribute("tagContext", child);
			super.render();
			// 重新设置
			request.setAttribute("tagContext", child.getParent());
		}
	}

}

第四步编写工具类TagNestContext

public class TagNestContext {
	private Object[] tags = null;

	private TagNestContext parent = null;

	private List<TagNestContext> children = null;

	public Object[] getTags() {

		return tags;

	}

	public void setTags(Object[] para) {

		this.tags = para;

	}

	public TagNestContext getParent() {

		return parent;

	}

	public void setParent(TagNestContext parent) {

		this.parent = parent;

	}

	public List<TagNestContext> getChildren() {

		if (children == null)
			children = new ArrayList<TagNestContext>();

		return children;

	}

	public void setChildren(List<TagNestContext> children) {

		this.children = children;

	}

}

 

猜你喜欢

转载自y398649217.iteye.com/blog/2345227