Am 19.08.2011 14:21, schrieb Mathilde Pellerin:
Hi all,

I have a form with a Radiogroup :

In my form, I have a radiogroup like this :
         RadioGroup<String>  genre = new
RadioGroup<String>("genreDestinataire");
         genre.setRequired(true);
         genre.setLabel(new Model<String>("Genre destinataire"));
         genre.add(new Radio<String>("femme", new Model<String>("f")));
         genre.add(new Radio<String>("homme", new Model<String>("h")));
         genre.add(new Radio<String>("mixte", new Model<String>("b")));
         form.add(genre);

This radiogroup match the genreDestinataire field in Questionnaire Entity
(with a CompoundPropertyModel).

In my unit test, I try to check what radio is selected, but I don't find
how...
I can get Model Object from radioGroup like this :
         String genreObtenu =
((RadioGroup<String>)form.get("genreDestinataire")).getDefaultModelObjectAsString();

but it works even if none of radio is checked. It happen when I fill the
form with existant Questionnaire : radiogroup model is ok, but none of radio
is checked.
Before correct this bug, I want to reproduce it in test, but I didn't find
how to see if a radio is checked or not : I didn't find any method like
"isChecked" or "isSelected" on Radio Component.

Is there any way to check that ?

Thanks.
M.

Maybe you can get the component from last renderered page (by path to component) and cast it to radio. Then you can compare raw input of group with the radio value (see Radio.onComponentTag).

Other option would be to use the tag tester provided by WicketTester. See

    /**
* Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags
     * instead of just the first.
     *
     * @see BaseWicketTester#getTagByWicketId(String)
     */
public static List<TagTester> getTagsByWicketId(WicketTester tester, String wicketId)
    {
return TagTester.createTagsByAttribute(tester.getServletResponse().getDocument(),
            "wicket:id", wicketId, false);
    }

Hth
Mike

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

Reply via email to