You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jean-Baptiste Quenot <jb...@apache.org> on 2007/09/03 16:31:41 UTC

Re: Palette and FormTester

* mperham:
> 
> It's hackish but this modified selectMultiple works for me:
> 
> 	public void selectMultiple(String formComponentId, int[] indexes)
> 	{
> 		checkClosed();
> 
> 		// This is a hack to get Palette selection working with FormTester.
> 		// Note we can't reference the palette class directly since FormTester
> 		// is in wicket and Palette is in wicket-extensions so we need to do
> 		// some acrobatics to deal with this.
> 		Component c = (Component) workingForm.get(formComponentId);
> 		if (!(c instanceof FormComponent)) {
> 			// Palette is not a FormComponent
> 			FormComponent recorder = (FormComponent) workingForm.get(formComponentId
> + ":recorder");
> 			String recorderValue = recorder.getValue();
> 			IChoiceRenderer renderer = (IChoiceRenderer)callGetter(c,
> "getChoiceRenderer");
> 			Collection choices = (Collection)callGetter(c, "getChoices");
> 			List choiceList = new ArrayList(choices);
> 			for (int i = 0; i < indexes.length; i++)
> 			{
> 				int j = indexes[i];
> 				Object value = choiceList.get(j);
> 				String val = renderer.getIdValue(value, j);
> 				recorderValue += val; 
> 				if (i + 1 < indexes.length) {
> 					recorderValue += ",";
> 				}
> 			}
> 			setFormComponentValue(recorder, recorderValue);
> 			return;
> 		}
> 		FormComponent fc = (FormComponent) c;
> 		ChoiceSelector choiceSelector =
> choiceSelectorFactory.createForMultiple(fc);
> 
> 		for (int i = 0; i < indexes.length; i++)
> 		{
> 			choiceSelector.doSelect(indexes[i]);
> 		}
> 	}
> 	
> 	private Object callGetter(Object self, String method) {
> 		try
> 		{
> 			Method m = self.getClass().getMethod(method, null);
> 			return m.invoke(self, null);
> 		}
> 		catch (Exception e)
> 		{
> 			throw new RuntimeException(e);
> 		}
> 	}

Dear Mike,

If FormTester is missing a feature to work with the Palette, why
not submitting a patch in JIRA?

Thanks in advance,
-- 
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/

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