I think you have to pass the form to the behavior in some way or you can do
something like this..but it is ugly in some way :)


1. in the form panel

 AjaxFormSubmitBehavior behave = new AjaxFormSubmitBehavior(form,
"onchange") {
            ...
            public void renderHead(IHeaderResponse response) {
                super.renderHead(response);
                response.renderJavascript("function submit_my_form(){\n" +
getEventHandler().toString() + "\n}", "submit_my_form");
            }
        };

form.add(behave);


...

2. anywhere in the page

and your button will look like this:

<input type="button" value="my_button" onclick="submit_my_form()"/>




On Mon, Jan 18, 2010 at 12:22 PM, Martin Asenov <mase...@velti.com> wrote:

> Hi, Alexandru, thanks for the quick reply.
>
> I get
>
> java.lang.IllegalStateException: form was not specified in the constructor
> and cannot be found in the hierarchy of the component this behavior is
> attached to
>
> the form is located in the same page and displayed, but it's actually
> placed within a panel that is a child of the page. :-(
>
> BR,
>
> -----Original Message-----
> From: Alexandru Barbat [mailto:alexandrubar...@gmail.com]
> Sent: Monday, January 18, 2010 11:26 AM
> To: users@wicket.apache.org
> Subject: Re: submit a form from outside of it
>
> Hi,
>
> Try this:
>
> AjaxFormSubmitBehavior behave = new AjaxFormSubmitBehavior(myForm,
> "onclick") {
>            protected void onSubmit(AjaxRequestTarget target) {
>                //do what you have to do
>            }
>
>
>        };
>
>
> Button submitButton = new Button("submitButton");
>
> submitButton.add(behave);
>
> ...
>
> Alexandru
>
> 2010/1/18 Martin Asenov <mase...@velti.com>
>
> > Hello, everyone!
> >
> > I have a form that has validation and so on, but the main difference to
> > ordinary forms is that my form does not contain it's submit button. It's
> > located in a parent, in my case a web page.
> >
> > I'm wondering how can I force the form submitting from the page. The code
> > is
> >
> > submitButton = new AjaxButton("submit_button) {
> >         protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
> >                   myForm.processForm();
> >         }
> > };
> >
> > The method processForm() in myForm just calls process();
> >
> > But nothing happens, looks like I'm missing something...
> >
> > Thanks,
> > Martin
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to