Package pl.zgora.uz.wmie.fe.gui.common.tag

Source Code of pl.zgora.uz.wmie.fe.gui.common.tag.Filter

package pl.zgora.uz.wmie.fe.gui.common.tag;

import java.util.HashMap;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import pl.zgora.uz.wmie.fe.gui.common.bean.FilterBean;
import pl.zgora.uz.wmie.fe.gui.common.statics.StaticFIelds;
import pl.zgora.uz.wmie.fe.gui.common.util.MessageUtil;

public class Filter extends BodyTagSupport {
  private PageContext pageContext;
  private Tag parent;
  private String id;
  private String htmlTag;
  private String visible;
  private String type;
  private Object data;
  private String label;

  int i = 0;

  public Filter() {
    super();
  }

  public int doStartTag() throws JspException {
    return SKIP_BODY;
  }

  public int doEndTag() throws JspException {
    BodyContent body = getBodyContent();
    Table table = (Table) getParent().getParent();
    try {
      if (label != null) {
        if (StaticFIelds.NO.equals(visible)) {
          htmlTag = "";
        } else {
          htmlTag = MessageUtil.getMessage(label, pageContext
              .getRequest().getLocale());
        }
      }

      if (StaticFIelds.NO.equals(visible)) {
        if (type.compareToIgnoreCase("select") == 0) {
          htmlTag += "<select id=\"" + id
              + "\" class=\"hideTableFilter\">";
          htmlTag += "<option selected=\"selected\" value=\"\">";
          htmlTag += "</option>";

          HashMap<String, String> selectData = (HashMap<String, String>) pageContext
              .getRequest().getAttribute(data.toString());
          for (String key : selectData.keySet()) {
            htmlTag += "<option value=\"" + key + "\">";
            htmlTag += selectData.get(key);
            htmlTag += "</option>";
          }
          htmlTag += "</select>";
        } else {
          htmlTag += " <input type=\"text\" id=\"" + id
              + "\" class=\"hideTableFilter\">";
        }
      } else {
        if (type.compareToIgnoreCase("select") == 0) {
          htmlTag += "<select id=\"" + id + "\">";
          htmlTag += "<option selected=\"selected\" value=\"\">";
          htmlTag += "</option>";

          HashMap<String, String> selectData = (HashMap<String, String>) pageContext
              .getRequest().getAttribute(data.toString());
          for (String key : selectData.keySet()) {
            htmlTag += "<option value=\"" + key + "\">";
            htmlTag += selectData.get(key);
            htmlTag += "</option>";
          }
          htmlTag += "</select>";
        } else if (type.compareToIgnoreCase("input") == 0) {
          htmlTag += " <input type=\"text\" id=\"" + id + "\">";
        }
      }
      FilterBean filterBean = new FilterBean();
      filterBean.setBody(htmlTag);
      filterBean.setName(id);
      table.getFilters().add(filterBean);

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return EVAL_PAGE;
  }

  public Tag getParent() {
    return parent;
  }

  public void release() {
    // TODO Auto-generated method stub

  }

  public void setPageContext(PageContext pageContext) {
    this.pageContext = pageContext;

  }

  public void setParent(Tag parent) {
    this.parent = parent;

  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getVisible() {
    return visible;
  }

  public void setVisible(String visible) {
    this.visible = visible;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }

  public String getLabel() {
    return label;
  }

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

  // private boolean contains(FilterBean filterBean,List<FilterBean> list){
  // boolean result = false;
  // for(FilterBean f : list){
  // if(filterBean.getName().equals(f.getName())){
  // return true;
  // }
  // }
  // return result;
  //   
  // }
}
TOP

Related Classes of pl.zgora.uz.wmie.fe.gui.common.tag.Filter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.