how to create a custom event
hai gmitev,
u just simply use this method.........
events.addForward("onClick", "self", "onClickAdd");
hi hari,
there is no such method as addForward in Events class?
I have tried putting,
comp.addEventListener(Constants.SHOPPING_BASKET_UPDATE_EVENT, this);
in doAfterCompose() method of the controller that is the listener and I have overriden onEvent() method, other events are getting in there but not my custom event.
From the calling controller, I do
Events.sendEvent(new Event(Constants.SHOPPING_BASKET_UPDATE_EVENT, self));
What am I missing? Still no luck.
I dont want to hard code the call to the other controller as this is NOT elegant, and if more controllers wish to listen for this event this seems the best way, if it can work.
what is "self" in this case, is it same instance of "this"
provide a reproducible code, don't let everybody guess your code.
i have provided the code, those are the lines of interest, and yes self is same instance of "this".
When something happens in one controller, i wish to notify all listeners (controllers) of the change.
Sounds simple enough, but how?
yes, simple enough and isn't reproducible , isn't ?
dennis, what do you mean? isn't reproducible?
In general how would you notify other controllers of an event without calling them directly?
Who knows what happened if I only got 2 line code?
I am not saying this isn't a bug of ZK,
But, who knows which part did the mistake? maybe ZK bug, maybe you did some thing wrong.
There are too many side effects in any program isn't it?
I am trying to help you, but ....I don't want to GUESS what could cause this.
Help me is helping youself if you can provide a reproducible code, not just 2 line code in different controller.
I ran into the same problem, and after looking at the source code I learned that the event name must simply begin with "on" and the third character must be upper case.
So for example, use a constant like:
final static String MY_EVENT = "onMyEvent";
and then
someComponent.addEventListener(MY_EVENT, new MyEventListener());
works just fine at runtime.
I use this model to synchronize Panels and Windows that need to show consistent data, like master-details, etc.
Very good catch, jdee. The error is raised in AbstractComponent.addEventListener, which does exactly the above mentioned check.
If we would have had the stacktrace, it would have been only two posts in this thread.
Here is the check implementation:
public static final boolean isValid(String name) {
return name != null && name.length() > 2
&& name.charAt(0) == 'o' && name.charAt(1) == 'n'
&& Character.isUpperCase(name.charAt(2));
}
ZK - Open Source Ajax Java Framework
I would like to notify a controller that some data in another controller has changed, however I do wish the two controllers to know about each other.
I was thinking that I could do somthing like:-
Controller A:
Events.postEvent(new Event(MY_EVENT, self, null));
Controller B:
self.addEventListener(MY_EVENT, this);
But I get an error:
Invalid event name: MY_EVENT
Do i need to register my event somewhere/somehow???