Skip to content

Commit

Permalink
使用BodyTag
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix committed Mar 8, 2016
1 parent c534606 commit 8b16d08
Show file tree
Hide file tree
Showing 8 changed files with 1,089 additions and 810 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.bintray"
apply plugin: "com.jfrog.artifactory"
apply plugin: 'optional-base'
apply plugin: 'nebula.optional-base'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:2.2.+'
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,112 +1,127 @@
package edu.scup.web.servlet.tags.easyui;

import org.springframework.web.servlet.tags.RequestContextAwareTag;
import org.springframework.web.servlet.tags.form.TagWriter;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.Map;

public abstract class AbstractHtmlElementTag extends RequestContextAwareTag {
public static final String KEY_JS = "js";
public static final String FUNC_FORMATTER_PREFIX = "formatter_";
public static final String DATA_DEFINE_PREFIX = "data_define_";
public static final String VALUE_MAP_KEY = "GRID_MAP";

protected String cssClass;
protected String cssStyle;
protected String title;
protected String width;
protected String height;

/**
* Provide a simple template method that calls {@link #createTagWriter()} and passes
* the created {@link org.springframework.web.servlet.tags.form.TagWriter} to the {@link #writeTagContent(org.springframework.web.servlet.tags.form.TagWriter)} method.
*
* @return the value returned by {@link #writeTagContent(org.springframework.web.servlet.tags.form.TagWriter)}
*/
@Override
protected final int doStartTagInternal() throws Exception {
return writeTagContent(createTagWriter());
}

protected void writeOptionalAttributes(TagWriter tagWriter) throws JspException {
tagWriter.writeOptionalAttributeValue("style", cssStyle);
tagWriter.writeOptionalAttributeValue("title", title);
tagWriter.writeOptionalAttributeValue("id", id);
tagWriter.writeOptionalAttributeValue("width", width);
tagWriter.writeOptionalAttributeValue("class", cssClass);
}

protected TagWriter createTagWriter() {
return new TagWriter(this.pageContext);
}

@SuppressWarnings("unchecked")
protected StringBuilder getSnippets(String key) {
TagSupport tag = getEDataGridTag();
Map<String, StringBuilder> map = (Map<String, StringBuilder>) tag.getValue(VALUE_MAP_KEY);
StringBuilder sb = map.get(key);
if (sb == null) {
sb = new StringBuilder();
map.put(key, sb);
}
return sb;
}

protected EDataGridTag getEDataGridTag() {
Tag tag = this;
while (!EDataGridTag.class.equals(tag.getClass())) {
tag = getParent();
}
return (EDataGridTag) tag;
}

/**
* Subclasses should implement this method to perform tag content rendering.
*
* @return valid tag render instruction as per {@link javax.servlet.jsp.tagext.Tag#doStartTag()}.
*/
protected abstract int writeTagContent(TagWriter tagWriter) throws JspException;

public void setCssClass(String cssClass) {
this.cssClass = cssClass;
}

public String getCssClass() {
return cssClass;
}

public String getCssStyle() {
return cssStyle;
}

public void setCssStyle(String cssStyle) {
this.cssStyle = cssStyle;
}

public void setTitle(String title) {
this.title = title;
}

public String getTitle() {
return title;
}

public void setWidth(String width) {
this.width = width;
}

public String getWidth() {
return width;
}

public String getHeight() {
return height;
}

public void setHeight(String height) {
this.height = height;
}
}
package cn.wujc.web.servlet.tags.easyui;

import edu.scup.web.servlet.tags.easyui.EDataGridBodyTag;
import org.springframework.web.servlet.tags.RequestContextAwareTag;
import org.springframework.web.servlet.tags.form.TagWriter;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.Map;

public abstract class BaseHtmlElementBodyTag extends RequestContextAwareTag implements BodyTag {
public static final String KEY_JS = "js";
public static final String FUNC_FORMATTER_PREFIX = "formatter_";
public static final String DATA_DEFINE_PREFIX = "data_define_";
public static final String VALUE_MAP_KEY = "GRID_MAP";

private BodyContent bodyContent;

protected String cssClass;
protected String cssStyle;
protected String title;
protected String width;
protected String height;

/**
* Provide a simple template method that calls {@link #createTagWriter()} and passes
* the created {@link org.springframework.web.servlet.tags.form.TagWriter} to the {@link #writeTagContent(org.springframework.web.servlet.tags.form.TagWriter)} method.
*
* @return the value returned by {@link #writeTagContent(org.springframework.web.servlet.tags.form.TagWriter)}
*/
@Override
protected final int doStartTagInternal() throws Exception {
return writeTagContent(createTagWriter());
}

protected void writeOptionalAttributes(TagWriter tagWriter) throws JspException {
tagWriter.writeOptionalAttributeValue("style", cssStyle);
tagWriter.writeOptionalAttributeValue("title", title);
tagWriter.writeOptionalAttributeValue("id", id);
tagWriter.writeOptionalAttributeValue("width", width);
tagWriter.writeOptionalAttributeValue("class", cssClass);
}

protected TagWriter createTagWriter() {
return new TagWriter(this.pageContext);
}

@SuppressWarnings("unchecked")
protected StringBuilder getSnippets(String key) {
TagSupport tag = getEDataGridTag();
Map<String, StringBuilder> map = (Map<String, StringBuilder>) tag.getValue(VALUE_MAP_KEY);
StringBuilder sb = map.get(key);
if (sb == null) {
sb = new StringBuilder();
map.put(key, sb);
}
return sb;
}

protected EDataGridBodyTag getEDataGridTag() {
Tag tag = this;
while (!EDataGridBodyTag.class.equals(tag.getClass())) {
tag = getParent();
}
return (EDataGridBodyTag) tag;
}

/**
* Subclasses should implement this method to perform tag content rendering.
*
* @return valid tag render instruction as per {@link javax.servlet.jsp.tagext.Tag#doStartTag()}.
*/
protected abstract int writeTagContent(TagWriter tagWriter) throws JspException;

public void setCssClass(String cssClass) {
this.cssClass = cssClass;
}

public String getCssClass() {
return cssClass;
}

public String getCssStyle() {
return cssStyle;
}

public void setCssStyle(String cssStyle) {
this.cssStyle = cssStyle;
}

public void setTitle(String title) {
this.title = title;
}

public String getTitle() {
return title;
}

public void setWidth(String width) {
this.width = width;
}

public String getWidth() {
return width;
}

public String getHeight() {
return height;
}

public void setHeight(String height) {
this.height = height;
}

@Override
public void doInitBody() throws JspException {
// no op
}

@Override
public void setBodyContent(BodyContent bodyContent) {
this.bodyContent = bodyContent;
}
}
Loading

0 comments on commit 8b16d08

Please sign in to comment.