Exemple #1
0
  /**
   * This method should be implemented in any subclasses of this component interested in processing
   * parameters from an html post operation. The component should interogate the HttpServletRequest
   * for any parameters it is interested in and change its internal state to reflect the parms.
   *
   * @return true if this component is the one that submitted the page and false if not.
   * @param parms a HashTable containing all the parameters for the servlet.
   */
  public boolean processParms(Hashtable parms, int rowNo) throws Exception {

    Object parm = parms.get(getFullName());
    if (parm == null) return false;

    String[] command = (String[]) parm;

    if (command[0] == null || command[0].trim().equals("")) return false;

    String st[] = getLookupComponent();
    if (command[0].startsWith("changeMonth:")) {
      int monthInc = Integer.parseInt(command[0].substring(12));
      GregorianCalendar g = new GregorianCalendar(_currentYear, _currentMonth, 1);
      g.add(Calendar.MONTH, monthInc);
      CalendarMonthChangeEvent e =
          new CalendarMonthChangeEvent(
              this, _currentMonth, _currentYear, g.get(Calendar.MONTH), g.get(Calendar.YEAR));
      _calEvent = e;
      if (st != null) {
        _scrollTo = true;
        getPage().scrollToItem(getFullName() + "CalStart");
      }
    } else if (command[0].startsWith("selectDate:")) {
      String newDate = command[0].substring(11);
      int pos = newDate.indexOf("-");
      String day = newDate.substring(0, pos);
      String year = newDate.substring(pos + 1);

      int dayInt = Integer.parseInt(day);
      int yearInt = Integer.parseInt(year);

      GregorianCalendar g = new GregorianCalendar();
      g.set(Calendar.YEAR, yearInt);
      g.set(Calendar.DAY_OF_YEAR, dayInt);

      java.sql.Date d = new java.sql.Date(g.getTime().getTime());
      CalendarDateSelectedEvent e = new CalendarDateSelectedEvent(this, g, d);

      _calEvent = e;

      if (st == null) {
        _scrollTo = true;
        getPage().scrollToItem(getFullName() + "CalStart");
      } else {
        HtmlScriptGenerator gen = new HtmlScriptGenerator(getPage());
        String format = st[1];
        String dtString = null;
        if (format != null) {
          SimpleDateFormat df = new SimpleDateFormat(format);
          dtString = df.format(d);
        } else {
          dtString = d.toString();
        }
        getPage().writeScript(gen.generateReturnValueToLookupScript(dtString, ""));
      }
    }

    return true;
  }
  private String generatePopupHtml(int row) {
    if (_showDescription && _editHandle instanceof HtmlTextEdit) {
      String rowNo = row == -1 ? "" : "_" + row;
      ((HtmlTextEdit) _editHandle)
          .setOnChange(
              "var theSpan=document.getElementById(\'div"
                  + getFullName()
                  + rowNo
                  + "'); if (theSpan) theSpan.innerHTML=''; "
                  + getHiddenDescrFieldFullName(row)
                  + ".value='';");
      // ((HtmlTextEdit) _editHandle).setHighlightOnFocus(_highlightOnFocus);
    }

    if (_usePopup) {
      if (_visible && _enabled) {
        StringBuffer jsPopupVars = new StringBuffer();

        if (_editHandle != null) {
          jsPopupVars.append("obj=");
          jsPopupVars.append(this.getFormString());
          jsPopupVars.append(((HtmlComponent) _editHandle).getFullName());
          jsPopupVars.append(((row == -1) ? "" : ("_" + row)));
          jsPopupVars.append(";");
        }

        String urlParms =
            PARAM_LOOKUP_CONTROLLER
                + "=$jsp$"
                + ((JspController) this.getPage()).getSessionKey()
                + "&"
                + PARAM_LOOKUP_COMPONENT
                + "="
                + this.getName()
                + "&"
                + PARAM_LOOKUP_ROW
                + "="
                + row;

        jsPopupVars.append("url='");
        String lookupPageURL = getLookUpPageURL();
        jsPopupVars.append(lookupPageURL);
        if (lookupPageURL != null && lookupPageURL.indexOf("?") == -1) jsPopupVars.append("?");
        else jsPopupVars.append("&");
        jsPopupVars.append(urlParms);
        jsPopupVars.append("&" + PARAM_LOOKUP_VALUE + "='+escape(obj.value)");
        // pass any values from other components on the page if
        // necessary
        if (_popupURLLineValues != null) {
          for (int i = 0; i < _popupURLLineValues.size(); i++) {
            FormComponentInfo inf = (FormComponentInfo) _popupURLLineValues.elementAt(i);
            jsPopupVars.append("+'&");
            jsPopupVars.append(inf.attName);
            jsPopupVars.append("='+escape(");
            jsPopupVars.append(inf.compName);
            if (inf.isInDataTable) jsPopupVars.append("_" + row);
            jsPopupVars.append(".value)");
          }
        }
        // add extra parms to the component
        if (_extraParms != null) jsPopupVars.append("+" + _extraParms);
        jsPopupVars.append(";");
        HtmlScriptGenerator gen = new HtmlScriptGenerator((JspController) getPage());
        if (_useDiv)
          jsPopupVars.append(
              gen.generatePopupDivScript(
                  "url",
                  getPopupPosition(),
                  getPopupTop(),
                  getPopupLeft(),
                  getPopupWidth(),
                  getPopupHeight(),
                  _useModal,
                  _divBorderStyle,
                  (_divScrolling ? "auto" : "no"),
                  (HtmlComponent) _editHandle,
                  row));
        else
          jsPopupVars.append(
              gen.generateOpenPopupScript(
                  "url",
                  getPopupPosition(),
                  getPopupTop(),
                  getPopupLeft(),
                  getPopupWidth(),
                  getPopupHeight(),
                  _useModal,
                  _popupAttributes,
                  (HtmlComponent) _editHandle,
                  row));

        _browsePopupImageLink.setHref("javascript:" + jsPopupVars);
        return jsPopupVars.toString();
      }
    }
    return null;
  }