Hi Gary,
Hi,I am kind of new to Wicket and am having a difficult time finding some
decent info on creating optgroups within selects.I basically have a structured
list in my DB which in turn has children - perfect solution would be to use
dynamically generated optgroups with their children which will of course be
option tags.All the examples containing optgroups seem to have the optgroups
fixed in markup with no wicket:ids.Any thoughts would be most welcomed.Gary
I created a custom implementation of SelectOptions and SelectOption (in
wicket-extensions) that I use to render the optgroups. What I do is use
a wrapping object that contains the business object and the name of the
optgroup and if it is the first or last wrapping object with that
particular optgroup name.
Then I override the SelectOptions.newOption(...) to wire in my custom
CustomSelectOption. Note that newOption() is called in order for each
option in the list so tracking the last optiongroup name can be used to
determine if its changed or not. i.e. if the
Custom.SlectOption.startOptionGroup or the
CustomSelectOption.endOptionGroup parameter should be true or false.
This is the only change in the selectOption:
@Override
protected void onRender(MarkupStream markupStream) {
/*
* Write out the option group wrappings if this is the first or
last option in a particular group.
*/
if (startOptionGroup) {
getResponse().write("<optgroup label=\"" + optionGroupName +
"\">" + optionGroupName + "\n");
}
super.onRender(markupStream);
if (endOptionGroup) {
getResponse().write("</optgroup>\n");
}
}
The setting of the start and end flags are handled in
SelectOptions.newOption(...) and then the above code is used to render
the options into optiongroups.
Let me know if you need more details,
Regards,
Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org