-
FEATURED COMPONENTS
First time here? Check out the FAQ!
In a zul file I can add to a component onDrop="move(event.dragged)" which will call the method "move"
I am dynamically building a component and want to do the equivelant in code. However, I do not see a comparable way. I know I can do the following:
someComponent.addEventListener("onDrop", new EventListener())
but how do I specify the method to call e.g. "move(event.dragged)
if your composer was extended GenericFrowardComposer, then you can:
1. override doAfterCompose() method, and don't forget to call super.doAfterCompose() at first line.
2. in doAfterCompose() method body, do someComponent.addEventListener("onDrop", new EventListener())
that's it.
iansti - thanks for your reply, but I guess I did not make myself clear. I want to know, via code, how I can attach the method 'move(event dragged)'. In otherwords, through the zul file I can state onDrop="move(event.dragged)" which, somehow adds the method call to move. is there a code equivelant that will allow me to someComponent.addEventListener("onDrop", new EventListener()) and then attach the method call "move(event dragged")??
You mean your method is inside GenericForwardComposer and you want to use it in ZUL?
if that so, it's easy, because:
composerid = id + _separator + "composer";
The default separator is '$', so to access it in zscript is to call: id+"$composer" in your event Listener.
then, you can make your method to public and use it in Zscript.
that is not what I mean - another try:
In most of the examples for drag and drop there is an entry in the component description of the *.zul file like this:
onDrop="move(event.dragged)", which will call the method "move" passing the event dragged. This I understand completely.
Here is my situation - I am not creating the component within the *.zul file, instead I am creating the component dynamically. I do not see any api that allows me to set the move(event.dragged).
I tried someComponent.addEventListener("onDrop=move(event.dragged)", new EventListener()) but got an error.
Hope this is clearer. Forget about the *.zul file, I only mention it because it has the behavior I want to mimin dynamically in code onDrop="move(event.dragged)"
Oh, okay then try this:
someComponent.addEventListener(Events.ON_DROP, new EventListener(){ public void onEvent(DropEvent event) throws Exception { move(event.getDragged()); }});
I have worked out this way
someComponent.addEventListener(Events.ON_DROP, new EventListener<Event>(){
public void onEvent(Event event) throws Exception {
Component dragged = ((DropEvent) event).getDragged();
move(dragged);
}
});
Asked: 2010-05-29 21:39:44 +0800
Seen: 743 times
Last updated: Aug 05 '12