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

Reply via email to