Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2776

Enhancing RadioChoice input items with individual title and css class attributes

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4.7
    • Fix Version/s: 1.4.13, 1.5-M1, 1.5-M3
    • Component/s: wicket
    • Labels:

      Description

      Wicket is a great framework based on an excellent idea. It is a joy to work with. There are several existing components and most of them are very usable and customizable as much as possible, however there are still a few places for improvement. One of those is org.apache.wicket.markup.html.form.RadioChoice, where it is currently not possible to set HTML title and class attributes for the individual input tags. This would be a great feature for some client-side javascript frameworks, and in my case the JQuery star-rating plugin is even hard to use without these. For this purpose I have created my own private alternative for this component, but it would be good to have it included in wicket, so that others can benefit too.
      See below the changes I have performed to enable this feature! Please note that all changes are made so that current behavior is not changed only new optional behavior is added.
      Changes in method onComponentTagBody(...)
      ...
      // Add radio tag
      String title = getTitle(index, choice);
      String cssClass = getCssClass(index, choice);
      buffer.append("<input name=\"").append(getInputName()).append("\" type=\"radio\"");
      if (title != null)
      buffer.append(" title=\"").append(title).append("\"");
      if (cssClass != null)
      buffer.append(" class=\"").append(cssClass).append("\"");
      buffer.append((isSelected(choice, index, selected) ? " checked=\"checked\"" : ""));
      buffer.append((enabled ? "" : " disabled=\"disabled\""));
      buffer.append(" value=\"").append(id).append("\" id=\"").append(idAttr)
      .append("\"");
      ...
      Added two new methods:
      /**

      • Returns the title attribute to be output for the input tag with the given index and choice
      • value. By default this returns null, and so the title attribute won't be set, but this can be
      • overridden.
      • @param index
      • @param choice
      • @return title attribute to be used for the given input tag
        */
        protected String getTitle(int index, T choice) { return null; }

        /**
        * Returns the CSS class attribute to be output for the input tag with the given index and
        * choice value. By default this returns null, and so the class attribute won't be set, but this
        * can be overridden.
        *
        * @param index
        * @param choice
        * @return CSS class attribute to be used for the given input tag
        */
        protected String getCssClass(int index, T choice) { return null; }

        Attachments

          Activity

            People

            • Assignee:
              jdonnerstag Juegen Donnerstag
              Reporter:
              szabolcs Szádeczky-Kardoss Szabolcs
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified