Using @UiHandler annotation on static fields

36 views
Skip to first unread message

Alexander Orlov

unread,
Sep 19, 2011, 9:38:38 AM9/19/11
to google-we...@googlegroups.com
I have 

    @UiHandler("dialogOk")
    void dialogOk(final ClickEvent event) {
        // do something
    }

This is perfectly valid code if dialogOk is within THIS class but how can I add a ClickHandler to a static Widget that is defined in "another" class?

I want to avoid putting this code into "another" class or using the addClickHandler method within THIS class. Is there a way around?

Eric Metcalf

unread,
Sep 19, 2011, 11:23:32 AM9/19/11
to Google Web Toolkit
Why don't you want to do the 2 things you mentioned?


On Sep 19, 8:38 am, Alexander Orlov <alexander.or...@loxal.net> wrote:
> I have
>
> *    @UiHandler("dialogOk")*
> *    void dialogOk(final ClickEvent event) {*
> *        // do something*
> *    }*
> *
> *
> This is perfectly valid code if dialogOk is within THIS class but how can I
> add a ClickHandler to a static Widget that is defined in "another" class?
>
> I want to avoid putting this code into "another" class or using the *
> addClickHandler* method within THIS class. Is there a way around?

Alexander Orlov

unread,
Sep 19, 2011, 11:31:56 AM9/19/11
to google-we...@googlegroups.com


On Monday, September 19, 2011 5:23:32 PM UTC+2, Eric Metcalf wrote:
Why don't you want to do the 2 things you mentioned?

> I want to avoid putting this code into "another" class or using the *

In this case I have to make a method (that is called by dialogOk()) in THIS class static because it would be called from another class.
 
> addClickHandler* method within THIS class. Is there a way around?

Well, I suppose it's discouraged since @UiHandler was introduced? Also I really like to use declarative constructs (annotations) for those kind of things. 

However my preliminary solution is to use the boilerplaty addClickHandler(...) :(

I suppose @UiHandler simply doesn't support static fields yet?

gwa

unread,
Sep 19, 2011, 11:43:09 AM9/19/11
to google-we...@googlegroups.com
write a @UiHandler method in another class the widget is declared look stupid to me. (Cool, let's put 8 class with @UiHandler("widget") and let see which handler wins!)

Why don't you simply do the opposite?


    @UiHandler("dialogOk")
    void dialogOk(final ClickEvent event) {
        yourOtherClass.doSomething();
    }


Imagine your other class is an Activity (Presenter from MVP pattern), and you have a correcttly separated View / activity...

Alexander Orlov

unread,
Sep 20, 2011, 3:10:16 AM9/20/11
to google-we...@googlegroups.com


On Monday, September 19, 2011 5:43:09 PM UTC+2, gwa wrote:
    @UiHandler("dialogOk")
    void dialogOk(final ClickEvent event) {
        yourOtherClass.doSomething();
    }


Imagine your other class is an Activity (Presenter from MVP pattern), and you have a correcttly separated View / activity...

  1. I consider @UiHandler not a part of the Presenter (due to its annotation marker) like everything else in GWT that uses annotations.
  2. I wanted to know whether assigning a Handler to a static widget via @UiHandler is possible at all.
Reply all
Reply to author
Forward
0 new messages