0

There exists a GWT based application (without source code), and there is a need to manipulate its date-pickers. So I thought to use jQuery to do this, but the problem is GWT changes the DOM model after each ajax call, and I don't know how to be informed of that refreshes to use the jQuery to select the elements and do my stuff.

Is it possible to use jQuery for this work? Is there a better solution to manipulate elements of a GWT page without accessing its source code?

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
Amir Pashazadeh
  • 7,170
  • 3
  • 39
  • 69

3 Answers3

0

If you're looking for equivalent of jQuery selector ( $("p") ) GWT has DOM class dedicated for it, e.g DOM.getElementById("divID") selects element with given id.

Class provides a set of selectors, some of them: getChild(Element parent, int index) , getInnerText(Element elem), sinkEvents(Element elem, int eventBits) )

http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/DOM.html

Johnny
  • 154
  • 2
  • 13
0

how to be informed of that refreshes

you can try to hook into DOM changes. take a look at MutationObserver. one similar solution you can find here.

possible to use jQuery for this work

well, you don't have much choice :)

better solution to manipulate elements

I don't think so.

Community
  • 1
  • 1
hahn
  • 3,588
  • 20
  • 31
0

You can't do it in deterministic way. It is because:

  • GWT code is obfuscated after compilation and change JS code after every new release
  • You cannot access function/variable in compiled JS, due to above
  • Loading times varies. So even if you tried to wait some time and then manipulate DOM, you may get unexpected results. You cannot rely on this approach.

The only one way to accomplish this is to expose callback function in GWT such:

public native void onDatePickerLoaded(DatePicker picker) {/*-{
    if ($wnd.onDatePickerLoadedCallback) {
        return $wnd.onDatePickerLoadedCallback(picker);
    }
}-*/;

And then you can attach jQuery + custom callback function in your HTML. I don't see any other possibility.

mlewandowski
  • 802
  • 7
  • 14