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 IStyledChoiceRenderer<T> extends IChoiceRenderer<T> {
>  /**
>   * @param t
>   * @return String
>   */
>  public String getOptGroupLabel(T t);
>
>  /**
>   * @param t
>   * @return String
>   */
>  public String getOptionCssClassName(T t);
> }
>
>
> /**
>  * @author Martin
>  *
>  * @param <T>
>  */
> public class DropDownChoiceWithStylingOptions<T> extends DropDownChoice<T> {
>  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, IModel<T> 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, IModel<T> model,
>      IModel<? extends List<? extends T>> choices) {
>    super(id, model, choices);
>  }
>
>  /**
>   * @param id
>   * @param model
>   * @param data
>   * @param renderer
>   */
>  public DropDownChoiceWithStylingOptions(String id, IModel<T> model,
>      List<? extends T> data, IChoiceRenderer<? super T> renderer) {
>    super(id, model, data, renderer);
>  }
>
>  /**
>   * @param id
>   * @param model
>   * @param choices
>   */
>  public DropDownChoiceWithStylingOptions(String id, IModel<T> 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) {
>      IStyledChoiceRenderer<T> styledChoiceRenderer =
> (IStyledChoiceRenderer<T>) 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);
>  }
>
>  /**
>   * @param tmp
>   */
>  private void endOptGroup(AppendingStringBuffer tmp) {
>    // OptGroup ended
>    int start = tmp.lastIndexOf("</option>");
>    tmp.insert(start + 9, "</optgroup>");
>  }
> }
>
> **
> Martin
>
> **
> Martin
>
>
> 2010/3/2 Jan Eriksson <jneriks...@gmail.com>:
>> We're using a Select component
>> (org.apache.wicket.extensions.markup.html.form.select.Select) to
>> display two groups of SelectionOptions in a Form. I guess that is the
>> correct component to use when you want to group options and render
>> them in optgroup's?
>>
>> Anyway, we would like to test the form using FormTester but when i try
>> to select a value we get the following exception:
>>
>> org.apache.wicket.WicketRuntimeException: Selecting on the
>> component:'0:paymentFormForm:paymentType' is not supported.
>>        at org.apache.wicket.util.tester.FormTester.fail(FormTester.java:824)
>>        at 
>> org.apache.wicket.util.tester.FormTester.access$100(FormTester.java:59)
>>        at 
>> org.apache.wicket.util.tester.FormTester$ChoiceSelectorFactory.create(FormTester.java:308)
>> ..
>> ..
>>
>> and the test code:
>>
>> FormTester ft = tester.newFormTester("paymentForm", true);
>> ft.select("paymentType", 0); // paymentType is the id of the Select component
>>
>>
>> Any help would be appreciated!
>>
>> thanks,
>> jan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to