0

How do I add child elements to a org.apache.wicket.extensions.markup.html.form.select.SelectOption

I have tried the following:

SelectOption<String> wicketSelectOption = new SelectOption<String>("option", new Model<>(selectOption.getValue()));
wicketSelectOption.setRenderBodyOnly(false);
wicketSelectOption.setEscapeModelStrings(false);


Label label = new Label("optionLabel", "<i class=\"icon\"></i>" + selectOption.getLabel());
label.setEscapeModelStrings(false);

wicketSelectOption.add(label);

Result:

The < i > tag is completely ignored

Depzor
  • 1,126
  • 1
  • 12
  • 21
  • 1
    What are you trying to archieve here? A `SelectOption` belongs to an ` – OH GOD SPIDERS Mar 12 '18 at 14:27
  • @OHGODSPIDERS displaying an icon for each option – Depzor Mar 12 '18 at 14:34
  • Check out DropDownChoice, maybe it will help you. It could have a list of choices. – Alexei Stepanov Mar 13 '18 at 08:02

1 Answers1

0

You need to add optionLabel as a child in the markup:

<option wicket:id="option">
    <wicket:container wicket:id="optionLabel"/>
</option>

I would suggest to use something like:

<option wicket:id="option">
    <i wicket:id="optionIcon"/> <wicket:container wicket:id="optionLabel"/>
</option>

This way you have full control.

martin-g
  • 17,243
  • 2
  • 23
  • 35