示例#1
0
  /** @see javax.servlet.jsp.tagext.Tag#doEndTag() */
  public int doEndTag() throws JspException {
    getLogger().debug("TableTag: inizio doEndTag()");

    if (isParameterPresent()) {
      String link;
      if ((action != null) && !action.equals("")) {
        // String a=((HttpServletRequest) pageContext.getRequest()).getServletPath();
        // String b=((HttpServletRequest) pageContext.getRequest()).getRequestURI();
        String contextPath = ((HttpServletRequest) pageContext.getRequest()).getContextPath();
        link = contextPath + action;
      } else {
        link = ((HttpServletRequest) pageContext.getRequest()).getRequestURI();
      }

      String root = ((HttpServletRequest) pageContext.getRequest()).getContextPath();

      boolean showLinkB = showLink == null || !showLink.equals("false");

      // se la query è in esecuzione settiamo il flag isLoading anche su TableModel
      if (paginator.isLoading()) tableModel.setLoading(true);
      else tableModel.setLoading(false);

      String contextPath = ((HttpServletRequest) pageContext.getRequest()).getContextPath();

      HtmlTableFactory htmlTableFactory;
      if ((action != null) && (!action.equals(""))) {
        htmlTableFactory =
            new HtmlTableFactory(
                tableModel,
                styleClass,
                pageToShow,
                paginator.getMaxPageNumber(),
                link,
                root,
                showLinkB,
                textToShow,
                intestazione,
                paginator.getElementsFoundNumber(),
                pageToShowParamName,
                useSmartLoading,
                timeToRefresh,
                contextPath,
                refreshUrl,
                true,
                actionExportExcel,
                this.paginator.getMaxRowPage(),
                methodChangeNumElements);
      } else {
        htmlTableFactory =
            new HtmlTableFactory(
                tableModel,
                styleClass,
                pageToShow,
                paginator.getMaxPageNumber(),
                link,
                root,
                showLinkB,
                textToShow,
                intestazione,
                paginator.getElementsFoundNumber(),
                pageToShowParamName,
                useSmartLoading,
                timeToRefresh,
                contextPath,
                refreshUrl,
                this.paginator.getMaxRowPage(),
                methodChangeNumElements);
      }

      String HTMLCode = htmlTableFactory.getHTMLCode();

      // avg PROVA
      //			       if (!tableModel.isLoading()){
      //					ExcelTableFactory excelFactory=new ExcelTableFactory(tableModel);
      //					excelFactory.createExcel(pageContext);
      //			       }
      // fine PROVA

      // se i dati sono ancora in caricamento
      // mette in page context la pagina di refresh e il tempo di refresh
      if (useSmartLoading && this.tableModel.isLoading()) {
        System.out.println("setto refresh per pager:" + paginator.getAttributeKey());
        pageContext.setAttribute("refreshUrl", contextPath + refreshUrl, PageContext.REQUEST_SCOPE);
        pageContext.setAttribute("timeToRefresh", timeToRefresh, PageContext.REQUEST_SCOPE);

        // incrementa il numero dei queryExecutor in esecuzione
        // adesso lo fa il Paginator
      } else {

        // decrementa il numero dei queryExecutor in esecuzione
        // ora lo fa il Paginator

      }

      try {
        pageContext.getOut().print(HTMLCode);
      } catch (IOException e) {
        getLogger().error("TableTag::doEndTag()::IOException::" + e.getMessage());
        throw new JspTagException("errore scrittura codice HTML");
      }
    }
    getLogger().debug("TableTag: fine doEndTag()");

    return super.doEndTag();
  }
示例#2
0
  /**
   * Metodo che inizializza e ottiene le istanze degli oggetti necessari alla creazione della
   * tabella
   */
  private void initValues() throws Exception {
    getLogger().beginMethod("initValues()");

    paginator =
        new Paginator(
            (HttpServletRequest) pageContext.getRequest(),
            businessDelegateName,
            businessDelegateMethodName,
            parameterName,
            this.useSmartLoading);

    // se in sessione è stato inserito il valore desiderato per il numero di elementi per pagina usa
    // quello
    Object businessDelegateParameter =
        SessionManager.getAttribute(
            ((HttpServletRequest) pageContext.getRequest()).getSession(false), parameterName);

    String attributeKey =
        PagerUtils.getKeyPaginatorModel(
            businessDelegateName, businessDelegateMethodName, businessDelegateParameter);

    String sessParamNumElementsPerPage =
        (String) pageContext.getSession().getAttribute(attributeKey + "_paramNumElementsPerPage");
    if (sessParamNumElementsPerPage != null) {
      try {
        paginator.setMaxRowPage(Integer.parseInt(sessParamNumElementsPerPage));
      } catch (NumberFormatException e1) {
      }
    } else { // altrimenti usa il parametro impostato nel tag del pager, se è stato valorizzato

      // se è stato specificato l'attributo maxRowsToShow
      // lo imposto al paginator
      if (maxRowsToShow != null && !maxRowsToShow.trim().equals("")) {
        try {
          paginator.setMaxRowPage(Integer.parseInt(maxRowsToShow));
        } catch (NumberFormatException e1) {
        }
      } else
        try {
          paginator.setMaxRowPage(8);
        } catch (NumberFormatException e1) {
        }
    }
    // quale pagina devo visualizzare ?
    //		String page = (String) pageContext.getRequest().getParameter(
    //				"pageToShow");

    String page = null;
    if (page == null) {
      if (pageToShowParamName == null)
        page = (String) pageContext.getRequest().getAttribute("pageToShow");
      else {
        page = (String) pageContext.getRequest().getAttribute(pageToShowParamName);
      }

      if (page == null) page = (String) pageContext.getRequest().getParameter(pageToShowParamName);

      if (page == null || page.equals("")) {
        page = (String) pageContext.getRequest().getParameter("pageToShow");
      }
    }

    PagerModel pagerModel = null;
    if (page == null) {

      pagerModel =
          (PagerModel)
              SessionManager.getAttribute(
                  ((HttpServletRequest) pageContext.getRequest()).getSession(false), attributeKey);

      if (pagerModel == null) {
        pagerModel = new PagerModel();
        // pagerModel.setTableModel(tableModel);
        SessionManager.addAttribute(
            ((HttpServletRequest) pageContext.getRequest()).getSession(false),
            attributeKey,
            pagerModel);
      } else {
        page = pagerModel.getActualPage() + "";
      }
    }

    // se page non esiste o è un numero negativo, lo inizializzo ad 1
    if (page != null) {
      try {
        pageToShow = Integer.parseInt(page);
      } catch (NumberFormatException e) {
        pageToShow = 1;
      }
    } else {
      pageToShow = 1;
    }

    // pageContext.getRequest().setAttribute("pageToShow", "" + pageToShow);
    if (pageToShowParamName == null)
      pageContext.getRequest().setAttribute("pageToShow", "" + pageToShow);
    else {
      pageContext.getRequest().setAttribute(pageToShowParamName, "" + pageToShow);
    }

    getLogger().debug("TableTag::Visualizzo la pagina numero " + pageToShow);

    columns = new Vector();
    tableModel = new TableModel();

    if ((bundle != null) && (!bundle.equals(""))) {
      messages = MessageResources.getMessageResources(bundle);
    } else {
      messages =
          MessageResources.getMessageResources(
              "it.mef.eidos.intese.resources.ApplicationResources");
    }

    getLogger().debug("TableTag: fine initValues()");
  }
示例#3
0
  /**
   * @throws javax.servlet.jsp.JspException
   * @see javax.servlet.jsp.tagext.IterationTag#doAfterBody()
   */
  public int doAfterBody() throws JspException {

    getLogger().beginMethod("doAfterBody");

    if (isParameterPresent()) {
      try {
        if (pageToShow < 1) pageToShow = 1;
        paginator.requestAndStorePage(pageToShow);

      } catch (Exception e) {
        e.printStackTrace();
        getLogger().error("TableTag::doAfterBody() " + e.getMessage());

        // ALEX 02/11/2010
        // throw new JspException( e.getMessage() );
        JspException je = new JspException(StackTraceUtil.getStackTrace(e));
        throw je;
      }
      // A che serve questa if ????
      // Commento e metto il pezzo di sopra
      //			if (showLink != null && showLink.equals("false")) {
      //				try {
      //					paginator.requestAndStorePage(1);
      //				} catch (Exception e) {
      //					getLogger().error(
      //							"TableTag::doAfterBody() " + e.getMessage());
      //				}
      //			} else {
      //				try {
      //					paginator.requestAndStorePage(pageToShow);
      //				} catch (Exception e) {
      //					e.printStackTrace();
      //					getLogger().error(
      //							"TableTag::doAfterBody() " + e.getMessage());
      //					throw new JspException( e.getMessage() );
      //				}
      //			}

      Vector titles = prepareRowTitles();
      tableModel.setRowTitles(titles);

      try {
        tableModel.setRowsData(prepareRowsData(paginator.getList()));
      } catch (Exception e) {
        e.printStackTrace();
        getLogger().error(e);
        getLogger().error("SUGGEST: <<<Make sure that your TO extends InteseTO, please!! >>>");
        System.out.println("Exception in doAfterBody:" + e.getMessage());
        // System.out.println("SUGGEST: <<< Does your TO extends InteseTO? >>>");

        // ALEX ott-2010
        // throw new JspException( e.getMessage() ) prima;
        JspException je = new JspException(StackTraceUtil.getStackTrace(e));
        // je.setStackTrace(e.getStackTrace());
        throw je;
      }
      if (summary != null && !summary.trim().equals("")) {
        tableModel.setSummary(summary);
      } else {
        tableModel.setSummary(getMessageFromRB("message.pagerSummary"));
      }

      if (tableModel != null) paginator.passaTableModel(tableModel, columns);
    }
    getLogger().endMethod("doAfterBody");

    return super.doAfterBody();
  }