You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Grigorov <ma...@fredhopper.com> on 2008/02/26 18:20:49 UTC

Decorating Ajax(Fallback)Link

Hi,

I want to decorate AjaxLink with custom JavaScript: 

	@Override
	protected IAjaxCallDecorator getAjaxCallDecorator() {
		return new AjaxCallDecorator() {
			@Override
			public CharSequence decorateScript(final CharSequence script) {
				return "if (confirm('Are you sure?')) {" + script + " } ";
			}
		};
	}

But Ajax(Fallback)Link has a AjaxEventBehavior("onclick") that decorates
my AjaxCallDecorator with CancelEventIfNoAjaxDecorator...

So the final result is something like:
<a id="deleteSynonymExpressionLink11" onclick="if (confirm('Are you
sure?')) {var
wcall=wicketAjaxGet('../?wicket:interface=:0:synonymsForm:deleteSynonymExpressionLink::IBehaviorListener:0:1',null,null, function() {return Wicket.$('deleteSynonymExpressionLink11') != null;}.bind(this)); } return !wcall;" href="../?wicket:interface=:0:synonymsForm:deleteSynonymExpressionLink::ILinkListener::">Delete</a>


The problem is in " return !wcall" that is appended at the end by
CancelEventIfNoAjaxDecorator.postDecorateScript()

What is the best way to do such kind of functionality ?


Regards
Martin


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


Re: Decorating Ajax(Fallback)Link

Posted by Martin Grigorov <mc...@e-card.bg>.
Thanks Igor !

Just for the record: it should be "return false;" otherwise the browser
makes a request to <a>'s href (i.e. a non-Ajax call).

Additionally the same effect/code could be added with less code with
AttributePrepender (there is no such class in Wicket for now). 

deleteLink.add(new AttributePrepender("onclick", new Model("if (!
confirm('Are you sure?')) { return false; }"), " "));


AttributePrepender is a modified version of AttributeAppender.
I think it is useful for other cases too.
For example when you want to prepend element's class:

<span class="newClass oldClass">...</span>

AFAIK if newClass and oldClass have same properties then the first wins
(i.e. the ones defined in newClass will be taken into account).

Is it a good idea to add AttributePrepender in Wicket? 

Martin


On Tue, 2008-02-26 at 10:21 -0800, Igor Vaynberg wrote:
> you can use an early exit instead
> 
> if (!confirm('foo')) return;
> 
> -igor
> 
> 
> On Tue, Feb 26, 2008 at 9:20 AM, Martin Grigorov
> <ma...@fredhopper.com> wrote:
> > Hi,
> >
> >  I want to decorate AjaxLink with custom JavaScript:
> >
> >         @Override
> >         protected IAjaxCallDecorator getAjaxCallDecorator() {
> >                 return new AjaxCallDecorator() {
> >                         @Override
> >                         public CharSequence decorateScript(final CharSequence script) {
> >                                 return "if (confirm('Are you sure?')) {" + script + " } ";
> >                         }
> >                 };
> >         }
> >
> >  But Ajax(Fallback)Link has a AjaxEventBehavior("onclick") that decorates
> >  my AjaxCallDecorator with CancelEventIfNoAjaxDecorator...
> >
> >  So the final result is something like:
> >  <a id="deleteSynonymExpressionLink11" onclick="if (confirm('Are you
> >  sure?')) {var
> >  wcall=wicketAjaxGet('../?wicket:interface=:0:synonymsForm:deleteSynonymExpressionLink::IBehaviorListener:0:1',null,null, function() {return Wicket.$('deleteSynonymExpressionLink11') != null;}.bind(this)); } return !wcall;" href="../?wicket:interface=:0:synonymsForm:deleteSynonymExpressionLink::ILinkListener::">Delete</a>
> >
> >
> >  The problem is in " return !wcall" that is appended at the end by
> >  CancelEventIfNoAjaxDecorator.postDecorateScript()
> >
> >  What is the best way to do such kind of functionality ?
> >
> >
> >  Regards
> >  Martin
> >
> >
> >  ---------------------------------------------------------------------
> >  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


Re: Decorating Ajax(Fallback)Link

Posted by Igor Vaynberg <ig...@gmail.com>.
you can use an early exit instead

if (!confirm('foo')) return;

-igor


On Tue, Feb 26, 2008 at 9:20 AM, Martin Grigorov
<ma...@fredhopper.com> wrote:
> Hi,
>
>  I want to decorate AjaxLink with custom JavaScript:
>
>         @Override
>         protected IAjaxCallDecorator getAjaxCallDecorator() {
>                 return new AjaxCallDecorator() {
>                         @Override
>                         public CharSequence decorateScript(final CharSequence script) {
>                                 return "if (confirm('Are you sure?')) {" + script + " } ";
>                         }
>                 };
>         }
>
>  But Ajax(Fallback)Link has a AjaxEventBehavior("onclick") that decorates
>  my AjaxCallDecorator with CancelEventIfNoAjaxDecorator...
>
>  So the final result is something like:
>  <a id="deleteSynonymExpressionLink11" onclick="if (confirm('Are you
>  sure?')) {var
>  wcall=wicketAjaxGet('../?wicket:interface=:0:synonymsForm:deleteSynonymExpressionLink::IBehaviorListener:0:1',null,null, function() {return Wicket.$('deleteSynonymExpressionLink11') != null;}.bind(this)); } return !wcall;" href="../?wicket:interface=:0:synonymsForm:deleteSynonymExpressionLink::ILinkListener::">Delete</a>
>
>
>  The problem is in " return !wcall" that is appended at the end by
>  CancelEventIfNoAjaxDecorator.postDecorateScript()
>
>  What is the best way to do such kind of functionality ?
>
>
>  Regards
>  Martin
>
>
>  ---------------------------------------------------------------------
>  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