实现一个自定义标签

   需求是有两个自定义的标签<table>和<column>

<table>有个items属性,负责导入数据

package hello;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class Column extends TagSupport {
    private String property;
    private String label;

    public int doStartTag() throws JspException {
        if (!(this.getParent() instanceof Table)) {
            throw new JspException("Column must be inside table.");
        }
        Map<String, String> column = new HashMap<String, String>();
        column.put("label", label);
        column.put("property", property);
        Table table = (Table) this.getParent();
        table.getColumns().add(column);
        return SKIP_BODY;
    }

    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public void setProperty(String property) {
        this.property = property;
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2021-08-10
  • 2021-06-24
  • 2022-02-09
  • 2022-01-10
  • 2022-12-23
  • 2021-10-17
  • 2022-02-17
猜你喜欢
  • 2021-11-02
  • 2022-12-23
  • 2021-06-05
  • 2022-01-16
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案
粤ICP备22038628号Powered By WordPress