Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-205

Change AbstractTextField to handle disabled fields better

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Won't Fix
    • 3.0
    • None
    • Framework
    • None
    • Operating System: Other
      Platform: Other
    • 30626

    Description

      I was wondering if a change I made to handle disable fields better could be an
      enhancement for the future for everyone.

      I found it helpful that if a field was disabled to generate the field with a
      special name and also generate a hidden field with the correct name and value,
      so that when the form is submitted the value for the field is not lost.

      Here is the code I used in the renderComponent method:

      String value;

      IForm form = getForm(cycle);

      // It isn't enough to know whether the cycle in general is rewinding,
      need to know
      // specifically if the form which contains this component is rewinding.

      boolean rewinding = form.isRewinding();

      // If the cycle is rewinding, but the form containing this field is not,
      // then there's no point in doing more work.

      if (!rewinding && cycle.isRewinding())
      return;

      // Used whether rewinding or not.

      String name = form.getElementId(this);

      if (rewinding)
      {
      // EG - 08/12/2004 if (!isDisabled())
      // EG - 08/12/2004 {
      value = cycle.getRequestContext().getParameter(name);

      // EG - 08/12/2004 Start Add
      if (value != null)

      { // EG - 08/12/2004 End Add updateValue(value); }

      return;
      }

      writer.beginEmpty("input");

      writer.attribute("type", isHidden() ? "password" : "text");

      if (isDisabled())
      // EG - 08/12/2004 Start Add

      { // EG - 08/12/2004 End Add writer.attribute("disabled", "disabled"); // EG - 08/12/2004 Start Add writer.attribute("name", name + "$Disabled"); }

      else

      { // EG - 08/12/2004 End Add writer.attribute("name", name); // EG - 08/12/2004 Start Add }

      // EG - 08/12/2004 End Add

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

      renderInformalParameters(writer, cycle);

      beforeCloseTag(writer, cycle);

      writer.closeTag();

      // EG - 08/12/2004 Start Add
      if (isDisabled())
      {
      if (value != null)

      { form.addHiddenValue(name, value); }

      else

      { form.addHiddenValue(name, ""); }

      }
      // EG - 08/12/2004 End Add

      Attachments

        Activity

          People

            Unassigned Unassigned
            ericglass@maximus.com Eric Glass
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: