⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabletag.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.faces.taglib;

import java.io.File;
import java.net.URL;

import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.webapp.UIComponentTag;

import com.esri.adf.web.data.WebApplication;
import com.esri.adf.web.util.WebUtil;
import com.esri.solutions.jitk.web.faces.component.TableControl;

/**
 * JSP tag for the {@link TableTag}.
 */
public class TableTag extends UIComponentTag {
  private String value;
  private URL xslUrl;
  private String mapId;
  private String pageSize;
  
  private void reset() {
    value = null;
    xslUrl = null;  
  }

  /**
   * Initializes the tag.
   */
  public TableTag() {
    reset();
  }

  /**
   * Resets the attribute values to defaults.
   */
  public void release() {
    super.release();
    reset();
  }

  /**
   * Return the component type string.
   * @return {@link String}- the component-type as defined in the faces-config.xml file
   */
  public String getComponentType() {
    return TableControl.COMPONENT_TYPE;
  }

  /**
   * Return the renderer type.
   * @return {@link String}- the renderer-type as defined in the faces-config.xml file
   */
  public String getRendererType() {
    return TableControl.COMPONENT_TYPE;
  }

  /**
   * Set the attributes of the {@link TableControl} from the tag attributes.
   * @param component the component to override properties
   */
  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    
    TableControl tableCtrl = (TableControl) component;    
    if (tableCtrl.isInit()) {
      return;
    }
    
    Application appl = WebUtil.getFacesContext().getApplication();
    if (value != null) {
      if (isValueReference(value)) {
          tableCtrl.setValueBinding("value", appl.createValueBinding(value));
      } else {
        throw new IllegalArgumentException("'value' attribute must be a value " +
                "binding expression.");
      }
    }
    
    if (xslUrl == null) {
      xslUrl = this.getClass().getClassLoader().getResource(
              WebApplication.XSL_DIR + "/" + TableControl.DEFAULT_XSL_FILE_NAME);
      if (xslUrl == null) {
        throw new IllegalArgumentException("XSL File '" + 
                TableControl.DEFAULT_XSL_FILE_NAME + "' not found.");
      }
    }
    tableCtrl.setXslUrl(xslUrl);

    if (mapId != null) {
        tableCtrl.setMapId(mapId);
    }
    if(pageSize != null)
    	tableCtrl.setPageSize(Integer.parseInt(pageSize));
    tableCtrl.setInit(true);
  }

  /**
   * Set the value binding expression for the map. The expression must 
   * evaluate to a WebTable.
   * 
   * @param value the value binding expression for the table
   */
  public void setValue(String value) {
    this.value = value;
  }

  /**
   * Sets the XSL file which renders the {@link TableControl}.  
   * The XSL file needs to be located in the xsl directory of the 
   * {@link WebApplication}.
   * @param xslFileName the XSL file name
   */
  public void setXslFile(String xslFileName) {
    String xslFileNameBound = bindAttribute(xslFileName);
    File xslFile = new File(xslFileNameBound);
    try {
      if (xslFile.isAbsolute()) {
        fileCheck(xslFile);
        xslUrl = xslFile.toURI().toURL();
      }else{
        xslUrl = this.getClass().getClassLoader().getResource(
                WebApplication.XSL_DIR + "/" + xslFileNameBound);
        if (xslUrl == null){
          xslUrl = this.getClass().getClassLoader().getResource(xslFileNameBound);
          if (xslUrl == null) {
            throw new IllegalArgumentException("File '" 
                    + xslFileNameBound + "' not found.");
          }
        }
      }
    } catch (Exception _) {
      throw new IllegalArgumentException(_.getMessage());
    }
  }
  
  /**
   * Sets the map control id associated with the control.
   * @param controlId the map control id.
   */
  public void setMapId(String mapId) {
    this.mapId = bindAttribute(mapId);
  }
  
  public void setPageSize(String pageSize) {
	    this.pageSize = bindAttribute(pageSize);
	  }

  private String bindAttribute(String attribute) {
    FacesContext fContext = WebUtil.getFacesContext();
    if (isValueReference(attribute))
      return (String) fContext.getApplication().createValueBinding(attribute).getValue(fContext);
    return attribute;
  }

  /**
   * Checks to see if the XSL file associated with this control exists.
   * @param file the XSL file for Map
   */
  private void fileCheck(File file) {
    if (!file.exists())
      throw new IllegalArgumentException("File '" 
              + file.getAbsolutePath() + "' not found.");
    if (!file.isFile())
      throw new IllegalArgumentException("The resource '" 
              + file.getAbsolutePath() + "' is not a file.");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -