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

Radio component throws an exception when used with RadioGroup and Label

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.5
    • Fix Version/s: 5.0.6
    • Component/s: tapestry-core
    • Labels:
      None

      Description

      Example code that breaks:
      <t:RadioGroup t:id="group1">
      <t:Radio t:id="radio1" t:value="value1"/><t:Label for="radio1"/>
      </t:RadioGroup>

      Exception is:
      No object of type org.apache.tapestry.RadioContainer is available from the Environment.

      The reason is that the Label validation rendering calls Radio.getElementName() after the RadioGroup has been popped from the environment.
      A simple fix is to cache the element name:

      private String _elementName;
      ...
      public String getElementName()

      { return _elementName; }

      ...
      void beginRender(MarkupWriter writer)

      { ... _elementName = _container.getElementName(); writer.element("input", "type", "radio", "id", _clientId, "name", _elementName, "value", value); ... }

      Cheers,
      Nick.

        Activity

        Hide
        chrislewis Chris Lewis added a comment -

        I can verify this behavior. My workaround is to simply use raw label tags.

        Show
        chrislewis Chris Lewis added a comment - I can verify this behavior. My workaround is to simply use raw label tags.
        Hide
        sicklittlemonkey Nick Westgate added a comment -

        This patch fixes Radio and adds tests (which fail without the fix).
        It simply caches the element name as described in the issue.

        The old test passed because the components were used in a loop.
        The test now additionally uses Radio, RadioGroup and Label with no enclosing loop.

        Cheers,
        Nick.

        Show
        sicklittlemonkey Nick Westgate added a comment - This patch fixes Radio and adds tests (which fail without the fix). It simply caches the element name as described in the issue. The old test passed because the components were used in a loop. The test now additionally uses Radio, RadioGroup and Label with no enclosing loop. Cheers, Nick.

          People

          • Assignee:
            hlship Howard M. Lewis Ship
            Reporter:
            sicklittlemonkey Nick Westgate
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development