0

I am trying to use GWTquery in my project. I have successfully added the jar file, added it to the class-path, imported all classes, but still nothing is working. Can anyone tell me what I am missing? Here is the code:

import static com.google.gwt.query.client.GQuery.*;
import com.google.gwt.query.client.plugins.Effects;
public class myfoo implements EntryPoint {
  public void onModuleLoad() {

        final TextBox tb = new TextBox();
        tb.setStyleName("foo"); 
        VerticalPanel panel = new VerticalPanel();
        panel.add(tb);
        $(".foo").setText("loo");
        $(".foo").click(new Function() {
            public boolean f(Event e) {
                tb.setText("foo");
                return true;  
            }
        });
        RootPanel.get().add(panel);
      }
     }

At pageload the text-box remains empty, not filled with loo. Aslo clicking on it has no effect.

SexyBeast
  • 7,913
  • 28
  • 108
  • 196

1 Answers1

1

I belive $(".foo") cannot match your text box has it hasn't yet been added to the document. Try moving the RootPanel.get().add(panel) line before the $(".foo") ones.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks. Another question, as per the documentat ion at http://code.google.com/p/gwtquery/wiki/CssGuide (towards the bottom), I can give a string CSS as a value to the `css` method rather than the type-safe Java ones. However doing that gives me completely different results than just defining them in CSS file. Why is that? – SexyBeast Jan 18 '13 at 14:25
  • "border: 1px solid #aaaaaa; border-radius: 5px; font-size: 80%; padding: 6px 3px 4px 3px; text-align: center;\r\n" + " -moz-transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;\r\n" + " box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset; background: #f1f1f1; margin: 20px 50px;" - This, when declared in a CSS file, renders a nice text box. But when I remove that and put it like `S(".foo").css(the_above_string)`, I don't get any effect at all.. – SexyBeast Jan 18 '13 at 14:26
  • Given the implementation of `Properties.create()`, it wouldn't surprise me that there are bugs or it doesn't support every CSS syntax subtleties. I see a "remove spaces" there, which would probably break your padding, transition, box-shadow and margin. BTW, I don't use GwtQuery. – Thomas Broyer Jan 18 '13 at 15:32
  • What did you mean by **I see a "remove spaces" there, which would probably break your padding, transition, box-shadow and margin.**? – SexyBeast Jan 18 '13 at 15:36
  • https://code.google.com/p/gwtquery/source/browse/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java#44 Reading more carefully, they shouldn't break your space-separated values though. But well, you already asked about that issue elsewhere, so let's not disseminate the information. – Thomas Broyer Jan 18 '13 at 15:43
  • I am seriously not getting this. What is space separated, and where? – SexyBeast Jan 18 '13 at 15:49
  • The `6px 3px 4px 3px` in `padding: 6px 3px 4px 3px` – Thomas Broyer Jan 18 '13 at 16:09
  • Oh. But there is no way to define 4 values without space-separating them, right? So how to do it? – SexyBeast Jan 18 '13 at 18:16