views:

452

answers:

1

Hi all, I have a situation where I need to integrate a gwt dialog (which to the best of my understanding is implemented as a div with z-index manipulation) into an existing html page.
There are two scenarios:
1. Which is the preferrable and more complicated is where i give the host html page another page which they embed as an iframe and I work my magic through there (maybe connect somehow to the parent window and plant my dialog I'm not sure).
2. Where I have limited access to the html page and I plant some code there which will load my dialog box.

Any ideas or thoughts on how I can implement these?
I've been working for a few months now with GWT and have found it quite nice although I have stayed far far away from the whole HTML area and until now all my work has been done strictly inside my java classes.
Thanks for any ideas and help handed
Ittai

A: 

I'll assume by dialog you mean a popup that is invisible at page load and made visible by, say, a click on something in the existing HTML. A simple strategy to make this happen is wrapping the existing HTML.

I have no experience with option 1. As for 2, all you need to alter in the existing HTML is adding the JS import, e.g.

<script type="text/javascript" language="javascript" src="/com.your.org.Module/com.your.org.module.client.Module.nocache.js"></script>

then adding an id to some clickable element you want to activate your dialog, e.g.

<button id="launchDialog">Show Dialog</button>

and finally adding an empty div with an id to insert your dialog into the DOM.

<div id="dialog"></div>

Then all you need in your Module is

public class Module implements EntryPoint {

    @Override
    public void onModuleLoad() {
        Button b = Button.wrap(DOM.getElementById("launchDialog"));
        b.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                RootPanel panel = RootPanel.get("dialog");
                Widget w = ... // your dialog widget here
                panel.add(w); 
            }
        });
    }

}

Lastly, you can play with the visibility of your popup div with the "display: none" style and the show() and hide() methods on the widget.

Bluu
Hi Bluu, first thanks for your answer. I've come to a similar conclusion by now but I would like to ask you (assuming option 2 is available) that the html page I'm integrating with is on another server (even IIS) is there a way to make this happen? How do I tell my module where my server is? assuming SOP is not an issueThanks a lot
Ittai
Sorry, I didn't notice your comment until now! So you're asking about loading your Javascript from another server entirely? Like <script type="text/javascript" language="javascript" src="http://www.yourgwtserver.com/com.foo.bar.Module/com.foo.bar.Module.nocache.js"></script> I can't really answer to that, as I've only loaded GWT from the same server (i.e. use a path on the server src="/com.foo.bar.Module/..."). Doesn't matter where you compiled GWT in that case. It'll figure out where it is.
Bluu
You can have the GWT component attach itself to divs remotely. Just make sure you use the "xs" linker (see http://code.google.com/webtoolkit/doc/latest/FAQ_Server.html#What_is_the_Same_Origin_Policy,_and_how_does_it_affect_GWT? ) I haven't done cross site linking with Button.wrap() but RootPanel.get("yourid").add(yourcomponent) works fine.If you do end up using the xs linker, there are other restrictions (you can't use code splitting is the main one).Hope this helps.
mooreds