Re: No JSNI method generated
On 16 avr, 07:01, dayre david.c.a...@gmail.com wrote: Vitali, this looks fairly straight forward... but now i'm having trouble wrapping this with a Composite so i can create my clickable list wiget. The issue is the HTML.wrap() which gives me an exception due to the element not being attached to the DOM ?... i'm missing something, but it's not apparent to me what it is and i'm having problems finding any solid examples in this list. Would you be so kind as to provide a version of your code wrapped in a class that extends Composite ? Instead of using the HTML widget and its wrap() method, extend Widget (and implements HasClickHandlers) and call the setElement from your ctor. class MyList extends Widget implements HasClickHandlers { public MyList() { // TODO: build your DOM tree here setElement(ulElement); } public HandlerRegistration addClickHandler(ClickHandler handler) { addDomHandler(handler, ClickEvent.getType()); } // Helper method, not strictly necessary but very helpful // You could either return a LIElement or the index of the item in the list as an int public int getItemFromEvent(DomEvent? event) { // TODO: see my previous message about how to implement it // see also the code for HTMLTable.getCellForEvent } } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
On 16 avr, 11:53, Vitali Lovich vlov...@gmail.com wrote: Is there a particular reason you recommend this approach as opposed to using the HTML widget? For something as simple as this, it seems like overkill to build-up a whole widget wrapping this when it doesn't seem to offer anything over using HTML. Well, the new wrap() constraints from GWT 1.6 are a reason (you cannot wrap an element that has an ancestor element which looks like a widget element). Building a specialized widget has also the advantage of the API you're exposing (be it to your own use only), otherwise why not go the low- level route wholly and use DOM.setEventListener and DOM.sinkEvents (and don't forget to call DOM.setEventListener(elt, null) on window close or you'll leak memory)? ...and creating a new widget is probably much easier than you'd think at first sight (even more with GWT 1.6 and its new event handlers) It's a matter of a) taste b) whether you're using widgets already (and might face the wrap() restriction) and c) what kind of code you're (dayre is) porting and how you want (he wants) it ported (rewrite using GWT widgets? or port the code without fully rewriting it). My understanding is that dayre wants to rewrite his jQuery-based app to GWT widgets, otherwise he would have used GQuery ;-) (or more seriously, he wouldn't have said The reason i'm not using existing GWT widgets, which my example doesn't show, is because i'm trying to attach an onclick() event to ordered list items (litext/li). There doesn't seem to be a widget which easily allows for this.) http://code.google.com/p/gwtquery/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
Is there a particular reason you recommend this approach as opposed to using the HTML widget? For something as simple as this, it seems like overkill to build-up a whole widget wrapping this when it doesn't seem to offer anything over using HTML. On Thu, Apr 16, 2009 at 5:07 AM, Thomas Broyer t.bro...@gmail.com wrote: On 16 avr, 07:01, dayre david.c.a...@gmail.com wrote: Vitali, this looks fairly straight forward... but now i'm having trouble wrapping this with a Composite so i can create my clickable list wiget.The issue is the HTML.wrap() which gives me an exception due to the element not being attached to the DOM ?... i'm missing something, but it's not apparent to me what it is and i'm having problems finding any solid examples in this list. Would you be so kind as to provide a version of your code wrapped in a class that extends Composite ? Instead of using the HTML widget and its wrap() method, extend Widget (and implements HasClickHandlers) and call the setElement from your ctor. class MyList extends Widget implements HasClickHandlers { public MyList() { // TODO: build your DOM tree here setElement(ulElement); } public HandlerRegistration addClickHandler(ClickHandler handler) { addDomHandler(handler, ClickEvent.getType()); } // Helper method, not strictly necessary but very helpful // You could either return a LIElement or the index of the item in the list as an int public int getItemFromEvent(DomEvent? event) { // TODO: see my previous message about how to implement it // see also the code for HTMLTable.getCellForEvent } } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
Write - good point regarding wrap. It's actually a restriction that's always been in effect, they just put in an assertion recently, from my understanding. On Thu, Apr 16, 2009 at 6:59 AM, Thomas Broyer t.bro...@gmail.com wrote: On 16 avr, 11:53, Vitali Lovich vlov...@gmail.com wrote: Is there a particular reason you recommend this approach as opposed to using the HTML widget? For something as simple as this, it seems like overkill to build-up a whole widget wrapping this when it doesn't seem to offer anything over using HTML. Well, the new wrap() constraints from GWT 1.6 are a reason (you cannot wrap an element that has an ancestor element which looks like a widget element). Building a specialized widget has also the advantage of the API you're exposing (be it to your own use only), otherwise why not go the low- level route wholly and use DOM.setEventListener and DOM.sinkEvents (and don't forget to call DOM.setEventListener(elt, null) on window close or you'll leak memory)? ...and creating a new widget is probably much easier than you'd think at first sight (even more with GWT 1.6 and its new event handlers) It's a matter of a) taste b) whether you're using widgets already (and might face the wrap() restriction) and c) what kind of code you're (dayre is) porting and how you want (he wants) it ported (rewrite using GWT widgets? or port the code without fully rewriting it). My understanding is that dayre wants to rewrite his jQuery-based app to GWT widgets, otherwise he would have used GQuery ;-) (or more seriously, he wouldn't have said The reason i'm not using existing GWT widgets, which my example doesn't show, is because i'm trying to attach an onclick() event to ordered list items (litext/li). There doesn't seem to be a widget which easily allows for this.) http://code.google.com/p/gwtquery/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
I got it now ! While i see the benefits of using GWT (Eclipse integration, App engine benefits, my backend app is Java, component model etc.) it is quite a paradigm shift to get my brain to think in Javascript terms while writing the client side Java code... + being somewhat spoiled (or ruined perhaps) by living in a JQuery world for so long where things are extremely succinct. The evolving API and lack of lower level examples has also been a bit of a stumbling block... but i'm hanging in there. Thank you both for your patience, and Thomas especially. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
On 15 avr, 15:25, dayre david.c.a...@gmail.com wrote: HI Vitali, Thank you for taking the time to respond. I very much appreciate it. The reason i'm not using existing GWT widgets, which my example doesn't show, is because i'm trying to attach an onclick() event to ordered list items (litext/li). There doesn't seem to be a widget which easily allows for this. Someone else in this group had suggested they do what i was trying to do. I'm trying to port an existing interface which i did in jquery() to GWT... one of the key components uses plain list items which i attach listeners to. While the JSNI path is (more than) OK when prototyping your port, I'd recommend you create a widget that suits your needs instead. You could also (now, or as part of the widget) take advantage of event bubbling: register a ClickHandler at the container level, look at the ClickEvent.getNativeEvent().getEventTarget() (it should be an Element, check with Element.is(...) and cast with Element.as(...)) and walk up the tree (getParent) until you find a LI (elem.getTagName ().equalsIgnoreCase(LIElement.TAG)) or your widget's element (getElement()). FYI, that's what the grids (Grid and FlexTable) in GWT do for the cell click events. What you explain makes sense and your option #2 for using the jsni name of the java function seems the easiest. I doubt it'll work (I'm almost sure it won't; JSNI reference resolving is done by parsing the JavaScript code, not using regexes and find/ replace). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
Vitali, this looks fairly straight forward... but now i'm having trouble wrapping this with a Composite so i can create my clickable list wiget.The issue is the HTML.wrap() which gives me an exception due to the element not being attached to the DOM ?... i'm missing something, but it's not apparent to me what it is and i'm having problems finding any solid examples in this list. Would you be so kind as to provide a version of your code wrapped in a class that extends Composite ? On Apr 15, 9:15 am, Vitali Lovich vlov...@gmail.com wrote: public LIElement appendLI(UListElement ul, String text) { LIElement li = Document.get().createLIElement(); li.setText(text); ul.appendChild(li); return li; } final UListElement ul = Document.get().createULElement(); final LIElement li1 = appendLI(ul, my text 1); final LIElement li2 = appendLI(ul, my text 2); HTML myList = HTML.wrap(ul); myList.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Element source = event.getRelativeElement(); if (source != null) { Window.alert(source.getInnerText() + clicked); } else { Window.alert(unexpected - event is relative to window); } } }); Problem solved using plain GWT you won't create memory leaks. On Wed, Apr 15, 2009 at 9:25 AM, dayre david.c.a...@gmail.com wrote: HI Vitali, Thank you for taking the time to respond. I very much appreciate it. The reason i'm not using existing GWT widgets, which my example doesn't show, is because i'm trying to attach an onclick() event to ordered list items (litext/li). There doesn't seem to be a widget which easily allows for this. Someone else in this group had suggested they do what i was trying to do. I'm trying to port an existing interface which i did in jquery() to GWT... one of the key components uses plain list items which i attach listeners to. What you explain makes sense and your option #2 for using the jsni name of the java function seems the easiest. I will also dig into the JSNI much deeper to fully understand how it works... i was trying to avoid that ;) Again thank you ! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
No, I'm not going to write your code for you. You need to first attach the elements to the actual DOM first just like the exception says. Any number of ways to do that: ul id=towrap/ul UListElement ul = (UListElement) DOM.getElementById(towrap) or UListElement ul = Document.get().createULElement(); Document.get().getBody().appendChild(ul); etc, etc On Thu, Apr 16, 2009 at 1:01 AM, dayre david.c.a...@gmail.com wrote: Vitali, this looks fairly straight forward... but now i'm having trouble wrapping this with a Composite so i can create my clickable list wiget.The issue is the HTML.wrap() which gives me an exception due to the element not being attached to the DOM ?... i'm missing something, but it's not apparent to me what it is and i'm having problems finding any solid examples in this list. Would you be so kind as to provide a version of your code wrapped in a class that extends Composite ? On Apr 15, 9:15 am, Vitali Lovich vlov...@gmail.com wrote: public LIElement appendLI(UListElement ul, String text) { LIElement li = Document.get().createLIElement(); li.setText(text); ul.appendChild(li); return li; } final UListElement ul = Document.get().createULElement(); final LIElement li1 = appendLI(ul, my text 1); final LIElement li2 = appendLI(ul, my text 2); HTML myList = HTML.wrap(ul); myList.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Element source = event.getRelativeElement(); if (source != null) { Window.alert(source.getInnerText() + clicked); } else { Window.alert(unexpected - event is relative to window); } } }); Problem solved using plain GWT you won't create memory leaks. On Wed, Apr 15, 2009 at 9:25 AM, dayre david.c.a...@gmail.com wrote: HI Vitali, Thank you for taking the time to respond. I very much appreciate it. The reason i'm not using existing GWT widgets, which my example doesn't show, is because i'm trying to attach an onclick() event to ordered list items (litext/li). There doesn't seem to be a widget which easily allows for this. Someone else in this group had suggested they do what i was trying to do. I'm trying to port an existing interface which i did in jquery() to GWT... one of the key components uses plain list items which i attach listeners to. What you explain makes sense and your option #2 for using the jsni name of the java function seems the easiest. I will also dig into the JSNI much deeper to fully understand how it works... i was trying to avoid that ;) Again thank you ! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: No JSNI method generated
No, that's wrong since the GWT compiler won't actually define clickTest but obfuscate it to save on bandwidth. You cannot do it that way. What you could do, if you were dead set on adding the HTML that way (if you're going to do it that way, why not just put it into the original HTML page?), you can do: public void onModuleLoad() { RootPanel.get().add(new HTML(h1 onclick=\return $wnd.h1ClickHandler(); \TEST/h1)); } private static native void registerOnClick() /*-- { $wnd.h1ClickHandler = function() { $wnd.alert(OK); } } --*/; Haven't tested but it should get you on the right track. Optionally, you could do it as: private static native String createH1(String text) /*-- { return 'h1 onclick=jsni name of java function' + text + '/h1; } --*/; I would recommend you read try to understand how JSNI works. the above is extremely redundant. Why aren't you using regular GWT widgets for this? JSNI is really not recommended for use unless you can explain why the same thing can't be accomplished in GWT. If you use JSNI, you're also more likely to cause memory leaks (pure GWT code will not leak memory). On Wed, Apr 15, 2009 at 12:56 AM, dayre david.c.a...@gmail.com wrote: I've been banging my head on this all day... i have a JSNI native method defined in my main EntryPoint class: /** * This is the entry point method. */ public void onModuleLoad() { RootPanel.get().add(new HTML(h1 onclick=\return clickTest(); \TEST/h1)); } public native void clickTest() /*-{ $wnd.alert(OK); }-*/; The page renders the TEST h1 HTML with the javascript onclick call but when i try to click on it, nothing happens... when i compile/browse and view in Firefox with firebug, firebug reports clickTest is not defined. I don't see the method defined anywhere in the generated code. Any ideas ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---