ok, well, I got it working. I moved things around some (stopped extending Anchor, and just added a click listener, set the URL of the link to "javascript:" after I saved it for later request, and ... added rb.send(); (it really helps if you actually send the request :)
I still would like to know what the common approach here is. -Abram On Feb 13, 1:39 pm, ricochet <[email protected]> wrote: > Hi, > > I'm wondering if someone can help me. I'm new to GWT, I'm very well > versed in Java, but less so in dealing with browsers/DOM/js. I expect > this is a common problem. > > What I'm trying to do is incorporate GWT into an existing app. (Don't > stop reading yet) I'll make this abstract: > > I have a TabPanel, with HTML widgets added on (the tabs). The HTML > has links in it, some of which send the user off the site (external > links), and some internal. For the internal links (which I know by > matching the href to my domain), instead of the browser following the > link, and replacing the entire page as it did pre-GWT, I'd like to > replace the internal links (read: add click listeners, and cancel the > event bubbling so the browser doesn't follow the link) with > asynchronous calls to get another HTML page, and replace the contents > of the *current tab* with the response. Essentially, I have HTML > pages with pagination links at the bottom. When a user goes to page > 2, I want to replace the tab ajax-ily. I'd rather not change server- > side code to help, as I want to have the option of not being tied to > GWT. So, how? > > I've tried this, and its not working, and I'm stuck - onBrowserEvent() > doesn't seem to be getting called. > > <code> > private void replaceLinks(final Element e) { > > NodeList<Element> anchors = e.getElementsByTagName("a"); > > for(int i = 0; i < anchors.getLength(); i++){ > > final AnchorElement ae = > AnchorElement.as(anchors.getItem(i)); > > > if(ae.getHref().startsWith("http://localhost:8080/myapp")){ > final String newHref = ae.getHref(); > Window.alert("attempting to *replace* link > of href: "+ae.getHref > ()); > > final Anchor a = new Anchor(ae){ > > @Override > public void onBrowserEvent(Event > event) { > Window.alert("1 got click, > sending request for: "+ae.getHref()); > super.onBrowserEvent(event); > event.cancelBubble(true); > > switch > (DOM.eventGetType(event)) { > case Event.ONCLICK: > Window.alert("got click, > sending request for: "+ae.getHref > ()); > RequestBuilder rb = new > RequestBuilder(RequestBuilder.GET, > newHref); //TODO localize URL > rb.setCallback(new > RequestCallback(){ > > public void > onError(Request request, > > Throwable exception) { > > > e.setPropertyString("currentURL", newHref); > > e.setInnerHTML("problem encountered -"+exception.getMessage > ()); > > } > > public void > onResponseReceived( > > Request request, > > Response response) { > > e.setPropertyString("currentURL", newHref); > > e.setInnerHTML(response.getText()); > > } > > }); > } > } > > }; > a.sinkEvents(Event.MOUSEEVENTS); //what > does sink event mean? > } > } > } > </code> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
