Details
Description
FormTester.selectMultiple only appends values, there is no way to replace or 'uncheck' items in a multiple select. This is contrary to the documentation in the source which does mention a toggle.
This is different from issue WICKET-1893. The solution there affects the model prior to submit().
Following are three methods that could be added to implement the toggle capability:
add to inner class
protected abstract class ChoiceSelector :
/**
- Implements removal of current selection(s) to allow toggle behaviour of assignValueToFormComponent.
- @param formComponent
- a <code>FormComponent</code>
*/
protected void doUnSelect() // should this be final? { // multiple selectable should remove unselected option(s) removeFormComponentValues(formComponent); }
add to FormTester
/**
- Simulates selecting multiple options for the <code>FormComponent</code>. The
- method only support multiple selectable <code>FormComponent</code>s.
- @see #select(String, int)
- @param formComponentId
- relative path (from <code>Form</code>) to the selectable
- <code>FormComponent</code>
- @param indexes
- index of the selectable option, starting from 0
- @param toggle
- set to <code>true</code> to clear existing selected option(s)
- set to <code>false</code> to append to existing selected option(s)
*/
public void selectMultiple(String formComponentId, int[] indexes, boolean toggle)
{
checkClosed();
ChoiceSelector choiceSelector = choiceSelectorFactory.createForMultiple((FormComponent)workingForm.get(formComponentId));
if (toggle)
{ choiceSelector.doUnSelect(); } selectMultiple(formComponentId, indexes);
}
add to FormTester
/**
- Removes <code>FormComponent</code>'s values from request parameter.
- @param formComponent
- a <code>FormComponent</code>
*/
private void removeFormComponentValues(FormComponent formComponent)Unknown macro: { if (parameterExist(formComponent)) { Map newParameters = new HashMap(); // could also get parameters from request and clear() newParameters.put(formComponent.getInputName(), new String[0]); baseWicketTester.getServletRequest().setParameters(newParameters); } }