/**
   * Restores the property to its default value. For {@link Direction#FORM} parameters, extracts the
   * property value and sets the binding form it (when appropriate).
   */
  public void resetParameter(IRequestCycle cycle) {
    if (_direction == Direction.FORM && cycle.isRewinding()) {
      IFormComponent component = (IFormComponent) _component;

      if (!component.isDisabled()) {
        IForm form = Form.get(cycle);

        if (form != null && form.isRewinding()) {
          Object value = readCurrentPropertyValue();

          _binding.setObject(value);
        }
      }
    }

    // Either way, clear the value.

    setPropertyValue(_clearValue);
  }
예제 #2
0
  protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
    IForm form = getForm(cycle);

    String name = form.getElementId(this);

    String format = getFormat();

    if (format == null) format = "dd MMM yyyy";

    SimpleDateFormat formatter = new SimpleDateFormat(format, getPage().getLocale());

    boolean disabled = isDisabled();

    if (!cycle.isRewinding()) {
      Body body = Body.get(cycle);

      if (body == null)
        throw new ApplicationRuntimeException(
            Tapestry.format("must-be-contained-by-body", "DatePicker"), this, null, null);

      Locale locale = getPage().getLocale();
      DateFormatSymbols dfs = new DateFormatSymbols(locale);
      Calendar cal = Calendar.getInstance(locale);

      Date value = getValue();

      Map symbols = new HashMap();

      symbols.put(SYM_NAME, name);
      symbols.put(SYM_FORMAT, format);
      symbols.put(SYM_INCL_WEEK, getIncludeWeek() ? Boolean.TRUE : Boolean.FALSE);

      symbols.put(SYM_MONTHNAMES, makeStringList(dfs.getMonths(), 0, 12));
      symbols.put(SYM_SHORT_MONTHNAMES, makeStringList(dfs.getShortMonths(), 0, 12));
      symbols.put(SYM_WEEKDAYNAMES, makeStringList(dfs.getWeekdays(), 1, 8));
      symbols.put(SYM_SHORT_WEEKDAYNAMES, makeStringList(dfs.getShortWeekdays(), 1, 8));
      symbols.put(SYM_FIRSTDAYINWEEK, new Integer(cal.getFirstDayOfWeek() - 1));
      symbols.put(SYM_MINDAYSINFIRSTWEEK, new Integer(cal.getMinimalDaysInFirstWeek()));
      symbols.put(SYM_FORMNAME, form.getName());
      symbols.put(SYM_VALUE, value);

      _script.execute(cycle, body, symbols);

      writer.beginEmpty("input");
      writer.attribute("type", "text");
      writer.attribute("name", name);
      writer.attribute("title", formatter.toLocalizedPattern());

      if (value != null) writer.attribute("value", formatter.format(value));

      if (disabled) writer.attribute("disabled", "disabled");

      renderInformalParameters(writer, cycle);

      writer.printRaw(" ");

      if (!disabled) {
        writer.begin("a");
        writer.attribute("href", (String) symbols.get(SYM_BUTTONONCLICKHANDLER));
      }

      IAsset icon = getIcon();

      writer.beginEmpty("img");
      writer.attribute("src", icon.buildURL(cycle));
      writer.attribute("border", 0);

      if (!disabled) writer.end(); // <a>
    }

    if (form.isRewinding()) {
      if (disabled) return;

      String textValue = cycle.getRequestContext().getParameter(name);

      if (Tapestry.isBlank(textValue)) return;

      try {
        Date value = formatter.parse(textValue);

        setValue(value);
      } catch (ParseException ex) {
      }
    }
  }