You should do it this way:
At first you'll need to create a class that implements
HasValueChangeHandlers interface. It is because of the fact that
ValueChangeEvent.fire() method requires a class that implements
HasValueChangeHandlers interface passed in a first parameter.
So let name that class MyHandlers (see below).

Then you should get an instance of MyHandlers class:
-----------------------
MyHandlers<String> exampleHandlers = new Handlers<String>();
-----------------------

and register ValueChangeHandler objects in that instance:
-----------------------
exampleHandlers.addValueChangeHandler(someHandler1);
exampleHandlers.addValueChangeHandler(someHandler2);
exampleHandlers.addValueChangeHandler(someHandler3);
-----------------------

Now you can fire ValueChangeEvent to all handlers that you've
registered in exampleHandlers object:
-----------------------
ValueChangeEvent.fire(exampleHandlers, "text");
-----------------------

MyHandlers class declaration:
-------------------------------------
public class MyHandlers<I> implements HasValueChangeHandlers<I> {

    private final List<ValueChangeHandler<I>> list = new
ArrayList<ValueChangeHandler<I>>();

    public void fireEvent(GwtEvent<?> event) {
        if (event instanceof ValueChangeEvent) {
            for (ValueChangeHandler<I> handler : list) {
                handler.onValueChange((ValueChangeEvent<I>) event);
            }
        }
    }

    public HandlerRegistration addValueChangeHandler(final
ValueChangeHandler<I> handler) {
        list.add(handler);
        return new HandlerRegistration() {

            public void removeHandler() {
                list.remove(handler);
            }
        };
    }
}
-------------------------------------

Hope that helps.
Best wishes!

On Aug 20, 4:33 am, jscheller <[email protected]> wrote:
> Hello -
>
> So, I've got a composite that has something like this inside it...
>
> private HandlerManager changeHandlers = new HandlerManager( null );
>
> public HandlerRegistration      addValueChangeHandler(ValueChangeHandler
> handler)
>    { return changeHandlers.addHandler(ValueChangeEvent.getType(),
> handler); }
>
> ...and somewhere down the pipeline, I want to actually fire off an
> event to anyone who registered a handler when the composite decides
> it's represented value has changed and wants the rest of the world to
> know. However, the syntax for actually constructing and firing the
> event off has got me pulling my hair out.
>
> I've tried variants of sending the event through the change
> handlers...
>
> changeHandlers.fireEvent( new ValueChangeEvent("foo") );
> changeHandlers.fireEvent( new ValueChangeEvent<String>("foo") );
>
> ...and using the static fire() method in the event class itself...
>
> ValueChangeEvent<String>.fire( changeHandlers, "foo");
>
> ...and Eclipse complains loudly about all of these constructions. I
> mean, I know this can't be that hard, but I can't find any good
> examples of things like this using the new (GWT 1.6 or later) event
> handlers, and reading the code sends me down a DOM event/Java generics
> rabbit hole that I'm frankly not experienced enough to deal with
> yet...
>
> Any help appreciated!
>
> Jim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to