コード例 #1
0
  @Override
  public int doStartTag() throws JspException {
    UIComponentTag tag = UIComponentTag.getParentUIComponentTag(pageContext);
    if (tag == null) {
      throw new JspException(
          _LOG.getMessage("FILEDOWNLOADACTIONLISTENER_MUST_INSIDE_UICOMPONENT_TAG"));
    }

    // Only run on the first time the tag executes
    if (!tag.getCreated()) return SKIP_BODY;

    UIComponent component = tag.getComponentInstance();
    if (!(component instanceof ActionSource)) {
      throw new JspException(
          _LOG.getMessage("FILEDOWNLOADACTIONLISTENER_MUST_INSIDE_UICOMPONENT_TAG"));
    }

    ELContextTag parentELContext = (ELContextTag) findAncestorWithClass(this, ELContextTag.class);

    Application application = FacesContext.getCurrentInstance().getApplication();

    FileDownloadActionListener listener = new FileDownloadActionListener();

    if (_filename != null) {
      listener.setValueExpression(FileDownloadActionListener.FILENAME_KEY, _filename);
    }

    if (_contentType != null) {
      listener.setValueExpression(FileDownloadActionListener.CONTENT_TYPE_KEY, _contentType);
    }

    listener.setMethod(_method);

    ((ActionSource) component).addActionListener(listener);

    return super.doStartTag();
  }