Thank you for the reply. Unfortunately this is not easier for me since
we already have this function implemented using the Select component.
If there is no way of getting FormTester to work with that component
i'll have a look at your code - i really want to have this test
automated without having to use a heavier test framework.
/jan
On Tue, Mar 2, 2010 at 10:48 AM, Martin Makundi
martin.maku...@koodaripalvelut.com wrote:
No, there is an easier way:
/**
* @author Martin
*
* @param T
*/
public interface IStyledChoiceRendererT extends IChoiceRendererT {
/**
* @param t
* @return String
*/
public String getOptGroupLabel(T t);
/**
* @param t
* @return String
*/
public String getOptionCssClassName(T t);
}
/**
* @author Martin
*
* @param T
*/
public class DropDownChoiceWithStylingOptionsT extends DropDownChoiceT {
private String previouslyAppendedOptGroupLabel;
private int choices;
/**
* @param id
* @param choices
* @param renderer
*/
public DropDownChoiceWithStylingOptions(String id,
IModel? extends List? extends T choices,
IChoiceRenderer? super T renderer) {
super(id, choices, renderer);
}
/**
* @param id
* @param choices
*/
public DropDownChoiceWithStylingOptions(String id,
IModel? extends List? extends T choices) {
super(id, choices);
}
/**
* @param id
* @param model
* @param choices
* @param renderer
*/
public DropDownChoiceWithStylingOptions(String id, IModelT model,
IModel? extends List? extends T choices,
IChoiceRenderer? super T renderer) {
super(id, model, choices, renderer);
}
/**
* @param id
* @param model
* @param choices
*/
public DropDownChoiceWithStylingOptions(String id, IModelT model,
IModel? extends List? extends T choices) {
super(id, model, choices);
}
/**
* @param id
* @param model
* @param data
* @param renderer
*/
public DropDownChoiceWithStylingOptions(String id, IModelT model,
List? extends T data, IChoiceRenderer? super T renderer) {
super(id, model, data, renderer);
}
/**
* @param id
* @param model
* @param choices
*/
public DropDownChoiceWithStylingOptions(String id, IModelT model,
List? extends T choices) {
super(id, model, choices);
}
/**
* @param id
* @param data
* @param renderer
*/
public DropDownChoiceWithStylingOptions(String id, List? extends T data,
IChoiceRenderer? super T renderer) {
super(id, data, renderer);
}
/**
* @param id
* @param choices
*/
public DropDownChoiceWithStylingOptions(String id, List? extends T
choices) {
super(id, choices);
}
/**
* @param id
*/
public DropDownChoiceWithStylingOptions(String id) {
super(id);
}
/**
* @see
org.apache.wicket.markup.html.form.AbstractChoice#onComponentTagBody(org.apache.wicket.markup.MarkupStream,
org.apache.wicket.markup.ComponentTag)
*/
�...@override
protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag) {
previouslyAppendedOptGroupLabel = null;
choices = getChoices().size();
super.onComponentTagBody(markupStream, openTag);
}
/**
* @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) {
IStyledChoiceRendererT styledChoiceRenderer =
(IStyledChoiceRendererT) getChoiceRenderer();
String currentOptGroupLabel =
styledChoiceRenderer.getOptGroupLabel(choice);
if (!Utils.equalsOrNull(currentOptGroupLabel,
previouslyAppendedOptGroupLabel)) {
// OptGroup changed
if (previouslyAppendedOptGroupLabel != null) {
endOptGroup(buffer);
}
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);
}
/**