You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by MYoung <cl...@live.com> on 2008/02/22 06:49:32 UTC

How to make a Form work both Ajax and no Ajax?

I have the Ajax stuff working in my form.  I want to use the same form
(placed on a WebPage) to handle when JS is off, I override the onSubmit()
for when JS is off.  But this must be wrong because the
AjaxFormSubmitBehavior no longer gets call, only the onSubmit is called.

        Form f = new Form("f", new CompoundPropertyModel(this)) {
        	@Override
        	public void onSubmit() {
        		handleRatingChanged(null);   // good when JS if off, but how to
make the Ajax stuff work
                                                               // when JS is
back on?
        	}
        };
        f.setOutputMarkupId(true);
        f.add(new TextField("rating", Integer.class));
        add(f);
  
        //
        // Ajax stuff, after the onSubmit is overridden in the form, this is
no longer work!
        //
        f.add(new AjaxFormSubmitBehavior("onsubmit") {
        	@Override
    		protected void onSubmit(AjaxRequestTarget target) {
    			handleRatingChanged(target);
    		}
        	@Override
    		protected void onError(AjaxRequestTarget target) {
    			
    		}
        	@Override
    		protected IAjaxCallDecorator getAjaxCallDecorator() {
    			return new AjaxCallDecorator() {
    				public CharSequence decorateScript(CharSequence script) {
    					return script + " return false;";	
    				}
    			};
    		}
        });



-- 
View this message in context: http://www.nabble.com/How-to-make-a-Form-work-both-Ajax-and-no-Ajax--tp15628207p15628207.html
Sent from the Wicket - User 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: How to make a Form work both Ajax and no Ajax?

Posted by richardwilko <ri...@gmail.com>.
You could use an AjaxFallbackButton on your form, eg:

		AjaxFallbackButton a = new AjaxFallbackButton("id", form)
		{
			@Override
			protected void onSubmit(AjaxRequestTarget target, Form form)
			{
				//normal stuff
				
				if(target != null)
				{
					//ajax stuff
				}
			}
		};
                form.add(a);


which should work with and without ajax.

Richard



MYoung wrote:
> 
> I have the Ajax stuff working in my form.  I want to use the same form
> (placed on a WebPage) to handle when JS is off, I override the onSubmit()
> for when JS is off.  But this must be wrong because the
> AjaxFormSubmitBehavior no longer gets call, only the onSubmit is called.
> 
>         Form f = new Form("f", new CompoundPropertyModel(this)) {
>         	@Override
>         	public void onSubmit() {
>         		handleRatingChanged(null);   // good when JS if off, but how to
> make the Ajax stuff work
>                                                                // when JS
> is back on?
>         	}
>         };
>         f.setOutputMarkupId(true);
>         f.add(new TextField("rating", Integer.class));
>         add(f);
>   
>         //
>         // Ajax stuff, after the onSubmit is overridden in the form, this
> is no longer work!
>         //
>         f.add(new AjaxFormSubmitBehavior("onsubmit") {
>         	@Override
>     		protected void onSubmit(AjaxRequestTarget target) {
>     			handleRatingChanged(target);
>     		}
>         	@Override
>     		protected void onError(AjaxRequestTarget target) {
>     			
>     		}
>         	@Override
>     		protected IAjaxCallDecorator getAjaxCallDecorator() {
>     			return new AjaxCallDecorator() {
>     				public CharSequence decorateScript(CharSequence script) {
>     					return script + " return false;";	
>     				}
>     			};
>     		}
>         });
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-make-a-Form-work-both-Ajax-and-no-Ajax--tp15628207p15630129.html
Sent from the Wicket - User 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