onValidate is fired by your form after all of fields have been
processed, your fields also trigger an validate event. You may want to
be more specific about which field/form your validate method is
intended to service.

Here is a test:

<t:form t:id="form">
    <t:loop source="1..3" index="index">
        <t:submit t:id="top" value="ok ${index}" defer="false"/>
    </t:loop>
    <t:textfield t:id="text1"/>
    <t:textfield t:id="text2"/>
    <t:textfield t:id="text3"/>
    <t:loop source="1..3" index="index">
        <t:submit t:id="ok" value="ok ${index}" defer="false"/>
    </t:loop>
</t:form>

    @Property
    private String text1;    @Property    private String text2;
@Property    private String text3;
    @Property    private int index;
    @Inject    private Logger log;

    @Inject
    private Environment environment;

    void onPrepare() {
        log.info("onPrepare()");
    }

    void onValidate() {
        log.info("onValidate()");
    }

    void onValidate(String value) {
        log.info("onValidate('{}')", value);
    }

    void onValidateFromText1(String value) {
        log.info("onValidateFromText1('{}')", value);
    }

    void onSelected() {
        log.info("onSelected()");
        FormSupport formSupport = environment.peek(FormSupport.class);
        formSupport.defer(new Runnable() {

            public void run() {
                log.info("onSelected() deferred");
            }
        });
    }

I typed a,b,c into the form fields, here is the output:

[INFO] pages.SubmitTests onPrepare()
[INFO] pages.SubmitTests onSelected()
[INFO] pages.SubmitTests onValidate('a')
[INFO] pages.SubmitTests onValidate()
[INFO] pages.SubmitTests onValidateFromText1('a')
[INFO] pages.SubmitTests onValidate('b')
[INFO] pages.SubmitTests onValidate()
[INFO] pages.SubmitTests onValidate('c')
[INFO] pages.SubmitTests onValidate()
[INFO] pages.SubmitTests onSelected() deferred
[INFO] pages.SubmitTests onValidate()


You can see that the onValidate is called for each field, in addition
to the single parameter onValidate, and the targeted
"onValidateFromText1".

Writing this example makes me think there should be a way to get the
component that is actually triggering an event. I don't think that's
currently possible...

Josh

On Tue, Nov 1, 2011 at 8:33 AM, George Christman
<gchrist...@cardaddy.com> wrote:
> Thanks Josh, I got it working. I do have one question though, I notice it
> runs things in the following order.
>
> onSelected
> onValidate
> formSupport.defer run code
> back to onValidate
> and back to onSelected
>
> Should I somehow be preventing it from rerunning the onValidate onSelected a
> second time?
>
> Thanks,
> George
>
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/Submit-inside-loop-tp4946513p4955519.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to