Thanks, That's a better place to attach validation. But it still leaves me working with a single String of comma separated selections. It makes me wonder if the underlying code can handle choices that contain commas.
-troy On Wed, Oct 7, 2009 at 4:27 PM, Igor Vaynberg <igor.vaynb...@gmail.com> wrote: > override newrecordercomponent() and add your validator there. > > -igor > > > On Wed, Oct 7, 2009 at 11:56 AM, Troy Cauble <troycau...@gmail.com> wrote: >> I'm trying to validate that at most 5 items were selected with a Palette >> but I've had a series of problems. (Wicket 1.3.7) >> >> palette.getRecorderComponent().add(myCompValidator) fails because >> getRecorderComponent() returns null. I think it's created in >> onBeforeRender() >> >> So I switched to form validation. >> >> recorder.getInput() returns a string of comma separated choices "x, y, z". >> recorder.getInputAsArray() returns an array of 1 containing the same string. >> I suppose I could parse these strings, but what if the choices have commas? >> >> recorder.getSelectedChoices() seems to "lag the state by one submit". >> (Second submit with 6 will fail. Second submit with 5 will succeed. >> gSC should probably only be used after validation.) >> >> So what's the right approach? >> Thanks, >> -troy >> >> >> final Palette pal1 = ..... >> >> form.add(new AbstractFormValidator() { >> private static final long serialVersionUID = 1L; >> �...@override >> public FormComponent[] getDependentFormComponents() >> { >> FormComponent out[] = new FormComponent[1]; >> out[0] = pal1.getRecorderComponent(); >> return out; >> } >> �...@override >> public void validate(Form form) >> { >> FormComponent r = pal1.getRecorderComponent(); >> System.err.println("INPUT: " + r.getInput()); >> String inputs[] = r.getInputAsArray(); >> System.err.println("ARRAY SIZE: " + inputs.length); >> System.err.println("ARRAY: " + inputs); >> System.err.println("ARRAY[0]: " + inputs[0]); >> >> /* always return 1 input string ?? >> if (inputs.length > 5) >> error(pal1.getRecorderComponent()); >> * */ >> Iterator it = pal1.getSelectedChoices(); >> int count = 0; >> while (it.hasNext()) >> { >> it.next(); >> if (++count > 5) >> { >> System.err.println("ERROR: " + count); >> error(pal1.getRecorderComponent(), "Max"); >> return; >> } >> System.err.println("COUNT: " + count); >> } >> } >> }); >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org