call onsubmit automatically

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

call onsubmit automatically

raju.ch
Hi,
I want to POST some data to a URL which internally redirects to a Page based on the POSTed params, for this I'm trying to do auto form submission but how to do it in wicket 1.4 or if you know other way which suits my requirement please let me know.

In javascript, we can do like this , but how to do it wicket 1.4. Please suggest.
<Script language="JavaScript"> function submitTheForm() { window.document.form1.submit(); } </script></head>
<body onload="submitTheForm();">
Reply | Threaded
Open this post in threaded view
|

Re: call onsubmit automatically

Sebastien
If you are have a Form (a wicket one) inside a Page, then you can do your
'submitTheForm()', because a simple 'submit()' suffice to post the form.
If your 'page' parameter you want to retrieve is bound to an Wicket
FormComponent (even an HiddenField), then you can retrieve it server side
and do a setResponsePage; you just have to get the right Page class from
the param and maybe construct your PageParameters also...

Hope this helps,
Sebastien.
Reply | Threaded
Open this post in threaded view
|

Re: call onsubmit automatically

raju.ch
Thnx for the reply sebastian, but I didn't get the solution what you suggested..Can you please explain it with an example?

thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: call onsubmit automatically

Sebastien
Hi again,

I maybe replied a little bit quickly (it was launch time :p). So, I meant
about something like this:

HTML:
    <body onload="window.document.getElementById('form').submit();">
        <form id="form" wicket:id="form">
          <input type="hidden" wicket:id="page" />
        </form>
    </body>

Java counterpart:
    private FormComponent<String> input;

    public HomePage(final PageParameters parameters) {

        final Form<Void> form = new Form<Void>("form") {

            private static final long serialVersionUID = 1L;

            @Override
            @SuppressWarnings("unchecked")
            protected void onSubmit()
            {
                String typeName = input.getModelObject(); //ie:
"com.mycompany.MyPage"
                Class<? extends Page> page = (Class<? extends Page>)
Class.forName(typeName); //!\ need to catch exception
                this.setResponsePage(page);
            }
        };
        this.add(form.setMarkupId("form")); //be careful, you have to set
the htmlId yourself because it is hard-coded in the javascript

        this.input = new HiddenField<String>("page", new
Model<String>(MyPage.class.getName()));
        form.add(this.input);
    }


Where MyPage is the page you want to redirect to.

Hope it answers your need.
Sebastien.


On Mon, Apr 30, 2012 at 12:34 PM, raju.ch <[hidden email]>wrote:

> Thnx for the reply sebastian, but I didn't get the solution what you
> suggested..Can you please explain it with an example?
>
> thanks in advance
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/call-onsubmit-automatically-tp4597765p4597836.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>