The solution is to nest the ListViews:

<select wicket:id="selectId">
        <wicket:container wicket:id="optGroups">
                <optgroup wicket:id="optGroup">
                <wicket:container wicket:id="options">
                        <option wicket:id="option"></option>


Select select = new Select(selectId);
select.add(new ListView("optGroups", transList) {

        protected void populateItem(ListItem item) {

        MyBean myBean = (MyBean) item.getModelObject();
        item.add(new OptGroup("optGroup", myBean.getName(), MyBean.getList()));


class OptGroup extends SelectOption {

        String label;

        List<MyBean2> list;

        public OptGroup(String id, String label, List<MyBean2> list) {
                this.label = label;
                this.list = list;

        private void init() {
                this.add(new ListView("options", list) {

                protected void populateItem(ListItem item) {
                        MyBean2 myBean2 = (MyBean2) item.getModelObject();
                        item.add(new CustomSelectOption("option", 


        protected void onComponentTag(final ComponentTag tag) {
             checkComponentTag(tag, "optgroup");
                        Select select = (Select) findParent(Select.class);
                        if (select == null) {
                                throw new WicketRuntimeException(
                                                "OptGroup component ["
                                                                + getPath()
                                                                + "] cannot 
find its parent Select. All OptGroup components must be
a child of or below in the hierarchy of a Select component.");

                tag.put("label", label);

public class CustomSelectOption extends SelectOption {
        public CustomSelectOption(String id, String displayValue) {
                super(id, new Model(displayValue));

        protected void onComponentTagBody(final MarkupStream markupStream, final
ComponentTag openTag) {
                replaceComponentTagBody(markupStream, openTag,

View this message in context:
Sent from the Users forum mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to