Hi!

Hmm.. mine seems to work fine with some other test cases, is this the
same code you have or is it different:

/**
   * @see 
org.apache.wicket.markup.html.form.AbstractChoice#appendOptionHtml(org.apache.wicket.util.string.AppendingStringBuffer,
java.lang.Object, int, java.lang.String)
   */
  @Override
  protected void appendOptionHtml(AppendingStringBuffer buffer, T choice,
      int index, String selected) {
    AppendingStringBuffer tmp = new AppendingStringBuffer(50);
    super.appendOptionHtml(tmp, choice, index, selected);

    if (getChoiceRenderer() instanceof IStyledChoiceRenderer) {
      IStyledChoiceRenderer<T> styledChoiceRenderer =
(IStyledChoiceRenderer<T>) getChoiceRenderer();

      String currentOptGroupLabel =
styledChoiceRenderer.getOptGroupLabel(choice);

      if (!Utils.equalsOrNull(currentOptGroupLabel,
previouslyAppendedOptGroupLabel)) {
        // OptGroup changed
        if (previouslyAppendedOptGroupLabel != null) {
          endOptGroup(tmp);
        }
        if (currentOptGroupLabel != null) {
          // OptGroup started
          int start = tmp.indexOf("<option");
          StringBuilder label = new
StringBuilder(currentOptGroupLabel.length() + 19);
          label.append("<optgroup
label=\"").append(currentOptGroupLabel).append("\">");
          tmp.insert(start, label);
        }
      }

      if ((currentOptGroupLabel != null) && (index == (choices-1))) {
        // Last option group must end too
        endOptGroup(tmp);
      }

      {
        String cssClass = styledChoiceRenderer.getOptionCssClassName(choice);
        if (cssClass != null) {
          int start = tmp.indexOf("<option");
          tmp.insert(start + 7, new StringBuilder("
class=\"").append(cssClass).append("\""));
        }
      }

      previouslyAppendedOptGroupLabel = currentOptGroupLabel;
    }

    buffer.append(tmp);
  }

**
Martin

2010/1/11 aditsu <[email protected]>:
>
> Hi, thanks for the quick reply.
>
>
> MartinM wrote:
>>
>>> There's a small bug - endOptGroup(tmp) for "OptGroup changed" actually
>>> closes
>>> the optgroup after the current option, not before.
>>
>> Note: It is supposed to close the previous optgroup. Not the current
>> optgroup.
>>
>
> Yep, that's why it's a bug. It actually starts a new optgroup and closes it
> after one option.
>
>
>
>> If there is a bug, can you give me your testcase?
>>
>
> Sure, here's the code:
>
>
> package test;
>
> import java.io.Serializable;
> import java.util.ArrayList;
> import java.util.List;
>
> import org.apache.wicket.markup.html.WebPage;
>
> public class TestPage extends WebPage {
>        private static class Val implements Serializable {
>                private static final long serialVersionUID = 1L;
>
>                private final String text;
>                private final String group;
>
>                public Val(final String text, final String group) {
>                        this.text = text;
>                        this.group = group;
>                }
>
>                public String getText() {
>                        return text;
>                }
>
>                public String getGroup() {
>                        return group;
>                }
>        }
>
>        private static final IStyledChoiceRenderer<Val> R = new
> IStyledChoiceRenderer<Val>() {
>                private static final long serialVersionUID = 1L;
>
>               �...@override
>                public String getIdValue(final Val object, final int index) {
>                        return String.valueOf(index);
>                }
>
>               �...@override
>                public Object getDisplayValue(final Val object) {
>                        return object.getText();
>                }
>
>               �...@override
>                public String getOptionCssClassName(final Val t) {
>                        return null;
>                }
>
>               �...@override
>                public String getOptGroupLabel(final Val t) {
>                        return t.getGroup();
>                }
>        };
>
>        public TestPage() {
>                final List<Val> list = new ArrayList<Val>();
>                for (int i = 0; i < 3; ++i) {
>                        for (int j = 0; j < 3; ++j) {
>                                list.add(new Val("text" + j, "group" + i));
>                        }
>                }
>                add(new DropDownChoiceWithStylingOptions<Val>("test", list, 
> R));
>        }
> }
>
>
> and the markup:
>
>
> <html xmlns:wicket>
> <body>
> <select wicket:id="test"></select>
> </body>
> </html>
>
>
>
> This is what it generates (I haven't stripped the wicket tags):
>
>
> <html xmlns:wicket>
> <body>
> <select wicket:id="test" name="test">
> <option selected="selected" value="">Choose One</option>
> <optgroup label="group0"><option value="0">text0</option>
> <option value="1">text1</option>
> <option value="2">text2</option>
> <optgroup label="group1"><option value="3">text0</option></optgroup>
> <option value="4">text1</option>
> <option value="5">text2</option>
>
> <optgroup label="group2"><option value="6">text0</option></optgroup>
> <option value="7">text1</option>
> <option value="8">text2</option></optgroup>
> </select>
> </body>
> </html>
>
>
> Adrian
> --
> View this message in context: 
> http://old.nabble.com/DropDownChoiceWithStylingOptions%3CT%3E-tp26642690p27112292.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to