Yes, this is bug/limitation, a better implementation may be:

        FormTester(final String path, final Form workingForm, final WicketTester wicketTester, boolean fillBlankString)
        {

        //....

        workingForm.visitFormComponents(new FormComponent.IVisitor() {
            public void formComponent(FormComponent formComponent) {
                // donothing for invisible component
                if (!formComponent.isVisibleInHierarchy()) {
                    return;
                }

                // not require gahter button value
                if (formComponent instanceof Button) {
                    return;
                }

                // if component is text field and do not have exist value, fill
                // blank String if required
                if (formComponent instanceof AbstractTextComponent) {
                    if ( Strings.isEmpty(formComponent.getValue())
                            && fillBlankString) {
                        tester.getServletRequest().setParameter(
                            formComponent.getInputName (), "");
                        return;
                    }
                }
            }
        });

FormTester should populate blank String only for visible, non-button and TextComponent.
And if AbstractTextComponent already contains value, it should not overwrite as blank String too.


On 4/14/06, Gustavo Hexsel < [EMAIL PROTECTED]> wrote:
  I think I've found a bug in FormTester.  Or maybe just a limitation.  When submitting a form you have no way of specifying the button that was actually clicked.  All buttons are marked as pressed, so the form visitor just finds the first one and marks it as the sender.  My suggestion is that FormTester shouldn't add a marker string to buttons, and a new submit(buttonName) method should be created.  I'd submit a formal patch, but I've never used 'patch' and the long weekend starts in an hour :)

  Here's the changes I'm proposing:
        FormTester(final String path, final Form workingForm, final WicketTester wicketTester, boolean fillBlankString)
        {
                this.path = path;
                 this.workingForm = workingForm;
                this.wicketTester = wicketTester;
                this.wicketTester.setupRequestAndResponse();

                if (fillBlankString)
                {
                         workingForm.visitFormComponents(new FormComponent.IVisitor()
                        {
                                public void formComponent(FormComponent formComponent)
                                {
                                        if ( formComponent.isEnabled() && !(formComponent instanceof Button)) { // JUST ADDED THE SECOND PART
                                                setValue(formComponent.getInputName(), "");
                                        }
                                }
                        });
                }
        }

   And the new submit method (keep the old one!):
        public void submit(String submitButtonPath) {
                checkClosed();
                try {
                        wicketTester.getServletRequest().setParameter(submitButtonPath, "marker");
                        wicketTester.getServletRequest().setRequestToComponent(workingForm);
                        wicketTester.processRequestCycle();
                } finally {
                        closed = true;
                }
        }

  Seems to have worked for my test cases.


    []s Gus




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmdlnk&kid0944&bid$1720&dat1642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user



--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen

Reply via email to