You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alex <av...@yahoo.com> on 2013/02/14 07:05:17 UTC

Several Form onSubmit, is it possible add via AbstractBehavior?

Hi. I have AjaxFallbackButton on the form with defined onSubmit handler.
There also one custom AbstractBehavior added  to the form. This Behavior
does some action with form's components (add event handlers for form's text
controls) and next should intercept form's onSubmit event to do some action
also. I try do this by adding form.AjaxFormSubmitBehavior(form, "onsubmit")
in this  AbstractBehavior (do this by override the onConfigure). As a result
only AjaxFormSubmitBehavior.onSubmit handler of MyCustomBehavior invoked but
form button's onSubmit is ignored. What is wrong in this case? Is it
possible to add additional onSubmit action to the form via custom Behavior
like in my case? 
Thanks for advice.

..................
form.add(new AjaxFallbackButton("submit",form) {
               protected void onSubmit(AjaxRequestTarget target, Form<?>
aForm) {
                      // some mail form submit actions....
               }
             });

form.add(new MyCustomBehavior(feedbackPanel));
..............

public class MyCustomBehavior extends AbstractBehavior {
       private FeedbackPanel feedback;
       private Form form;

       public MyCustomBehavior(FeedbackPanel feedback) {
             this.feedback = feedback;
       }

       @Override
        public void bind(Component component)  {
              super.bind(component)
              // here initialize form ....
              this.form = (Form) component;
        }

       @Override
	public void onConfigure(Component component) {
            // here form's text controls event handlers added via
AjaxFormComponentUpdationBehavior....
            this.form.add(new AjaxFormSubmitBehavior(this.form, "onsubmit")
{    
                        @Override
			protected void onSubmit(AjaxRequestTarget target) {
                               // form submit action, set flag of some
operation
                               // this onSubmit handler should be invoked
after main form onSubmit handler
                        } 
                        @Override
			protected void onError(AjaxRequestTarget target) {
                        }
            }
        }
}





--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Several-Form-onSubmit-is-it-possible-add-via-AbstractBehavior-tp4656347.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: Several Form onSubmit, is it possible add via AbstractBehavior?

Posted by Paul Bors <pa...@bors.ws>.
As per the JavaDocs:
http://ci.apache.org/projects/wicket/apidocs/1.5.x/org/apache/wicket/ajax/markup/html/form/AjaxFallbackButton.html#onSubmit(org.apache.wicket.ajax.AjaxRequestTarget,
org.apache.wicket.markup.html.form.Form)
Callback for the onClick event. If ajax failed and this event was generated
via a normal submission, the target argument will be null

*Parameters:*target - ajax target if this linked was invoked using ajax,
null otherwise
I belive your target is null because you are using a fallback button and
you might have JavaScript turned off in your browser?

~ Thank you,
   Paul Bors
On Fri, Feb 15, 2013 at 5:42 AM, Alex <av...@yahoo.com> wrote:

> As I understand the only way to catch the form's onSubmit is by analyze
> form
> components validation which is performed by form submitting. And if
> validation is successful then form submit will be done for sure. Am I
> correct understand?
>
> Trying to find workaround for this issue,in MyCustomBehavior I found form's
> button and added AjaxEvenBehavior("onclick") to it. Strangely but
> form.getDefaultButton() returned null and the only way to get form's Button
> component is the traversing over all the form components and finding a
> button component (not sure if it best way). So when I clicked the button
> the
> AjaxEventBehavior.onEvent occurs (in MyCustomBehavior) and next
> AjaxFallbackButton.onSubmit on main form had invoked. But I found that the
> target parameter is null in main onSubmit handler of form's
> AjaxFallbackButton. What wrong in this case? Why the target is null in
> form's buton handler and not null in the form Behavior's button handler.
> This is the same button in fact. In the form it have onSubmit handler, and
> in MyCustomBehavior it have onEvent handler. A piece of code is given
> below...
> Thanks a lot for help.
>
> public class MyCustomBehavior extends AbstractBehavior {
> ......
>        @Override
>         public void onConfigure(Component component) {
>             // this.form.getDefaultButton() - return null in fact (why)
>
>             Iterator<? extends Component> iter = form.iterator();
>             while (iter.hasNext()) {
>                         FormComponent<?> fc =
> (FormComponent<?>)iter.next();
>                         if (fc.isEnabled() && (fc instanceof Button)) {
>                                 fc.add(new AjaxEventBehavior("onclick") {
>                                         private static final long
> serialVersionUID = 1L;
>
>                                         @Override
>                                         protected void
> onEvent(AjaxRequestTarget target) {
>                                                 // here target is not null
>
> System.out.println("clicked !!!!");
>                                         }
>                                 });
>                                 };
>              } // end of while
>         } // end of onConfigure
> ....
> }
>
> // Main page
> ....
> form.add(new AjaxFallbackButton("submit",form) {
>                  protected void onSubmit(AjaxRequestTarget target, Form<?>
> aForm) {
>                         // here target is null (why?)
>                        .....
>                       // some main actions for form submit...
>                  }
> });
> .....
> form.add(new MyCustomBehavior(feedback));
> .......
> // End of main page
>
>
>
> -----
> Best wishes,
> Alex.
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Several-Form-onSubmit-is-it-possible-add-via-AbstractBehavior-tp4656347p4656393.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: Several Form onSubmit, is it possible add via AbstractBehavior?

Posted by Alex <av...@yahoo.com>.
As I understand the only way to catch the form's onSubmit is by analyze form
components validation which is performed by form submitting. And if
validation is successful then form submit will be done for sure. Am I
correct understand? 

Trying to find workaround for this issue,in MyCustomBehavior I found form's
button and added AjaxEvenBehavior("onclick") to it. Strangely but
form.getDefaultButton() returned null and the only way to get form's Button
component is the traversing over all the form components and finding a
button component (not sure if it best way). So when I clicked the button the
AjaxEventBehavior.onEvent occurs (in MyCustomBehavior) and next
AjaxFallbackButton.onSubmit on main form had invoked. But I found that the
target parameter is null in main onSubmit handler of form's
AjaxFallbackButton. What wrong in this case? Why the target is null in
form's buton handler and not null in the form Behavior's button handler.
This is the same button in fact. In the form it have onSubmit handler, and
in MyCustomBehavior it have onEvent handler. A piece of code is given
below...
Thanks a lot for help.

public class MyCustomBehavior extends AbstractBehavior { 
......
       @Override
	public void onConfigure(Component component) {
            // this.form.getDefaultButton() - return null in fact (why)

 	    Iterator<? extends Component> iter = form.iterator();
	    while (iter.hasNext()) {
			FormComponent<?> fc = (FormComponent<?>)iter.next();
			if (fc.isEnabled() && (fc instanceof Button)) {
				fc.add(new AjaxEventBehavior("onclick") {
					private static final long serialVersionUID = 1L;

					@Override
					protected void onEvent(AjaxRequestTarget target) {
                                                // here target is not null  
						System.out.println("clicked !!!!");
					}
				});
				};				
	     } // end of while 
        } // end of onConfigure
....
}

// Main page
....
form.add(new AjaxFallbackButton("submit",form) {
                 protected void onSubmit(AjaxRequestTarget target, Form<?> 
aForm) {
                        // here target is null (why?)
                       .....
                      // some main actions for form submit...
                 }
}); 
.....
form.add(new MyCustomBehavior(feedback));
.......
// End of main page



-----
Best wishes,
Alex.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Several-Form-onSubmit-is-it-possible-add-via-AbstractBehavior-tp4656347p4656393.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: Several Form onSubmit, is it possible add via AbstractBehavior?

Posted by Sven Meier <sv...@meiers.net>.
You could add a custom Behavior to your FormCompoments. Let this 
Behavior implement IValidator and it will get notice of a form submit 
via #validate().

Hope this helps
Sven

On 02/14/2013 07:05 AM, Alex wrote:
> Hi. I have AjaxFallbackButton on the form with defined onSubmit handler.
> There also one custom AbstractBehavior added  to the form. This Behavior
> does some action with form's components (add event handlers for form's text
> controls) and next should intercept form's onSubmit event to do some action
> also. I try do this by adding form.AjaxFormSubmitBehavior(form, "onsubmit")
> in this  AbstractBehavior (do this by override the onConfigure). As a result
> only AjaxFormSubmitBehavior.onSubmit handler of MyCustomBehavior invoked but
> form button's onSubmit is ignored. What is wrong in this case? Is it
> possible to add additional onSubmit action to the form via custom Behavior
> like in my case?
> Thanks for advice.
>
> ..................
> form.add(new AjaxFallbackButton("submit",form) {
>                 protected void onSubmit(AjaxRequestTarget target, Form<?>
> aForm) {
>                        // some mail form submit actions....
>                 }
>               });
>
> form.add(new MyCustomBehavior(feedbackPanel));
> ..............
>
> public class MyCustomBehavior extends AbstractBehavior {
>         private FeedbackPanel feedback;
>         private Form form;
>
>         public MyCustomBehavior(FeedbackPanel feedback) {
>               this.feedback = feedback;
>         }
>
>         @Override
>          public void bind(Component component)  {
>                super.bind(component)
>                // here initialize form ....
>                this.form = (Form) component;
>          }
>
>         @Override
> 	public void onConfigure(Component component) {
>              // here form's text controls event handlers added via
> AjaxFormComponentUpdationBehavior....
>              this.form.add(new AjaxFormSubmitBehavior(this.form, "onsubmit")
> {
>                          @Override
> 			protected void onSubmit(AjaxRequestTarget target) {
>                                 // form submit action, set flag of some
> operation
>                                 // this onSubmit handler should be invoked
> after main form onSubmit handler
>                          }
>                          @Override
> 			protected void onError(AjaxRequestTarget target) {
>                          }
>              }
>          }
> }
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Several-Form-onSubmit-is-it-possible-add-via-AbstractBehavior-tp4656347.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
>


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