You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "raju.ch" <ra...@gmail.com> on 2012/04/30 11:42:27 UTC

call onsubmit automatically

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.

</head>
<body onload="submitTheForm();">

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/call-onsubmit-automatically-tp4597765.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: call onsubmit automatically

Posted by Sebastien <se...@gmail.com>.
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 <ra...@gmail.com>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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: call onsubmit automatically

Posted by "raju.ch" <ra...@gmail.com>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: call onsubmit automatically

Posted by Sebastien <se...@gmail.com>.
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.