FormTester does not toggle selected values when using selectMultiple
--------------------------------------------------------------------
Key: WICKET-2104
URL: https://issues.apache.org/jira/browse/WICKET-2104
Project: Wicket
Issue Type: Bug
Components: wicket
Affects Versions: 1.3.5
Environment: Ubuntu 8.04, Java 1.6
Reporter: ray bon
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)
{
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);
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.