toggle behaviour

2 messages Options
Embed this post
Permalink
frank06

toggle behaviour

Reply Threaded More More options
Print post
Permalink
hi there,

i need to implement a "toggle" effect (http://docs.jquery.com/Effects/slideToggle) within a wicket page. i checked out wickext's latest trunk version but i haven't found it.

so i implemented my own:

public class SlideToggleEffect implements Effect {

        public String getEffectString() {
                return "slideToggle";
        }
       
}

but quite troublesome with the usage. i didn't find any examples of this (or similar).

what is not really clear to me, is the fact that the effects are triggered when the behaviour is added to the component - i doubt this is desirable.

for example, if i do:  comp.add(new EffectBehavior(new SlideToggleEffect(), EffectSpeed.SLOW);  and my comp to the page, then when i load the page on my browser i'll notice the effect (basically a slow slideUp, because the target div was already displayed).

how can i avoid this?  i mean, i just wanted to be able to associate a trigger (like the WickextEventBehavior) to a link and fire the effect from there.

i ultimately came up with a sort of workaround...

makeCommentLink.add(new WickextEventBehavior(MouseEvent.CLICK) {
                        @Override
                        public CharSequence callbackStatement() {
                                return makeCommentToggleEffectBehavior.getCallbackStatement();
                        }
                       
                });
                add(makeCommentLink);


and adding to EffectBehavior.java

        public CharSequence getCallbackStatement() {
                JavaScriptBuilder queryBuilder  = new JavaScriptBuilder();
                queryBuilder = new JavaScriptBuilder(component);
                queryBuilder.$().call(this);
                return queryBuilder.getStatement();
        }

but i don't feel this is clean. i still have to add the behaviour to my component, which triggers the effect on page loading. if i do this via an AjaxLink, and call: comp.add(slideToggleEffectBehavior);  target.addComponent(comp); -> each time this callback is executed, i add once again the behavior, and thus the effect is trigger more than once! after the second or third click you see it going up and down, up and down... which means i will have to keep some state and decide whether or not to update. this path seems too complex.

what's the proper (or intended) way of calling an effect? could you provide the "wickext approach" / best practice? can i just use it with standard onClick method of a Link and avoid the MouseEvent.CLICK?

thanks a lot! good work, btw.

francisco
Lionel Armanet

Re: toggle behaviour

Reply Threaded More More options
Print post
Permalink
Hi Fransisco,

I think that toggling an effect when the behavior is added is not the good way to do. In fact, we are releasing a new version of WickeXt to be closer to jQuery (I think it will be the 1.0 version) that will ease that kind of needs (you can ave a preview of the alpha documentation here: http://www.wickext.org/wickext-examples-1.0-SNAPSHOT/?wicket:bookmarkablePage=:org.odlabs.examples.core.Events).

For the moment, the only way to do this is to add an "onclick wickext behavior" and to generate the needed JavaScript.

I'll make an announcement when the new version is available.

Cya !