tel8618217223380 / gwtquery

Automatically exported from code.google.com/p/gwtquery
MIT License
0 stars 0 forks source link

live does not work before something is added to RootPanel #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

public void onModuleLoad() {
        $("button").live(Event.ONCLICK, new Function(){
              public boolean f(Event e) {
                  System.out.println("EVENT");
                  return false;
              }
            });
    FlowPanel myPanel = new FlowPanel();
    RootPanel.get().add(new FlowPanel(),100, 100);
        myPanel.add(new Button("Click"));
...

What is the expected output? What do you see instead?

Clicking should sysout 'EVENT'; nothing happens

This code works (the panel is added to the RootPanel before calling live):

public void onModuleLoad() {
    FlowPanel myPanel = new FlowPanel();
    RootPanel.get().add(new FlowPanel(),100, 100);

        $("button").live(Event.ONCLICK, new Function(){
              public boolean f(Event e) {
                  System.out.println("EVENT");
                  return false;
              }
            });
        myPanel.add(new Button("Click"));
...

What version of the product are you using? On what operating system?
gwt 2.1.1
gquery 1.0.0-2.1.0

Please provide any additional information below.

Original issue reported on code.google.com by mtrebi...@gmail.com on 15 Jul 2011 at 9:54

GoogleCodeExporter commented 9 years ago
Did no one encounter this problem or gQuery works when gQuery is defined before 
any element is put in the root panel?

Original comment by mtrebi...@gmail.com on 18 Jul 2011 at 7:56

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I didn't find time yet to investigate your problem but I suspect the 
RootPanel.get() as being the cause of your problem.

The first time you call RootPanel.get(), it creates a DefaultRootPanel widget 
and defines this widget as event listener for the body element and so removes 
the custom gwtquery eventlistener set on the body element by the live method.

Original comment by julien.d...@gmail.com on 19 Jul 2011 at 12:01

GoogleCodeExporter commented 9 years ago
I confirm... you have to call the live method after the initialization of the 
root panel. Otherwise, this initialization will remove the gwtquery event 
listener to set its own.

This code below works :
 public void onModuleLoad() {

    //force initialization of the RootPanel
    RootPanel.get();

    $("button").live(Event.ONCLICK, new Function() {
      public boolean f(Event e) {
        Window.alert("click");
        return false;
      }
    });

    FlowPanel myPanel = new FlowPanel();
    RootPanel.get().add(myPanel, 100, 100);
    myPanel.add(new Button("Click"));

  }

Original comment by julien.d...@gmail.com on 19 Jul 2011 at 9:23

GoogleCodeExporter commented 9 years ago
Is there a way to apply gquery on elements that are created in other java class?
let's say i have my main java.class that extends entry point. and inside this 
one i'm calling "header" class where i have different anchors. where do i need 
to put gquery declarations?

Original comment by mtrebi...@gmail.com on 22 Jul 2011 at 8:17

GoogleCodeExporter commented 9 years ago
Could you please ask your question in gwtquery group 
(http://groups.google.com/group/gwtquery) ? It's the best way to receive an 
answer and allow the other people to find easily response of already asked 
questions.

Thanks

Original comment by julien.d...@gmail.com on 22 Jul 2011 at 8:23