/** * Returns the first checked radio button with the specified name. If none of the radio buttons by * that name are checked, this method returns <tt>null</tt>. * * @param name the name of the radio button * @return the first checked radio button with the specified name */ public HtmlRadioButtonInput getCheckedRadioButton(final String name) { WebAssert.notNull("name", name); for (final HtmlRadioButtonInput input : getRadioButtonsByName(name)) { if (input.isChecked()) { return input; } } return null; }
/** * Selects the specified radio button in the form. Only a radio button that is actually contained * in the form can be selected. * * @param radioButtonInput the radio button to select */ void setCheckedRadioButton(final HtmlRadioButtonInput radioButtonInput) { if (!isAncestorOf(radioButtonInput) && !lostChildren_.contains(radioButtonInput)) { throw new IllegalArgumentException("HtmlRadioButtonInput is not child of this HtmlForm"); } final List<HtmlRadioButtonInput> radios = getRadioButtonsByName(radioButtonInput.getNameAttribute()); for (final HtmlRadioButtonInput input : radios) { if (input == radioButtonInput) { input.setAttribute("checked", "checked"); } else { input.removeAttribute("checked"); } } }