Opening a new Window with a Widget in GWT

14,298

Solution 1

The way i got this to work is as follows: i wrote a jsni method to open a new window

public static native BodyElement getBodyElement() /*-{
        var win = window.open("", "win", "width=940,height=400,status=1,resizeable=1,scrollbars=1"); // a window object
        win.document.open("text/html", "replace");

i added a basic body to the new window and returned the body element

win.document.write("<HTML><HEAD>"+css1+css2+"</HEAD><BODY><div class=\"mainpanel\"><div style=\"width: 100%; height: 54px;\"><div id=\"mainbody\"class=\"mainbody\" style=\"width: 100%;\"></div></div></div></BODY></HTML>");
        win.document.close(); 
        win.focus();
        return win.document.body;
    }-*/;

i then called this method from my main java method

BodyElement bdElement = getBodyElement();

I then injected my panel which has lots of widgets into the returned body element

SystemConfiguration config = new SystemConfiguration();             bdElement.getOwnerDocument().getElementById("mainbody").appendChild(config.getElement());

Solution 2

I agree with Bogdan: Use a DialogBox.

If you can't, you Window.open() as you mentioned in option 1:

  1. Create another GWT module, and form.html that will load it
  2. Window.open("form.html?entry=54")
  3. Have the form gwt module read from the URL, load the entry, allow it to be edited, and provide Save and Cancel buttons
  4. Close the popup when Save or Cancel is clicked
Share:
14,298
Primus
Author by

Primus

Updated on June 30, 2022

Comments

  • Primus
    Primus almost 2 years

    Before you start shooting me down i have checked for answers and i have googled till my fingers bled but i havent been able to find a simple, concise answer. So im asking again for all those that might have this problem.

    Question: how to open a new window with a formpanel in side.

    Context: i have an app that lists lots of items, i want someone to edit an entry, i want a new window to open so they can edit properties then hit save. A standard thing you find in a lot of applications.

    Architecture: I have one client module called UI, it has a dozen classes that draw widgets and fill a main area when selected from a menu. I have a single html page called UI.html which has the tag in the head. Thats it.

    Options Ive Seen

    1. Call Window.Open() but you need to define a html file. I dont have one. I can create an empty one but how do you inject a widget in to it ?

    2. use jsni $wnd to create a new window and get a reference to it. But how do i inject a form panel into it ??

    3. use a popuppanel. They look sucky - plus if opening a window through JS is quite simple i would expect it to be in gwt.

    Maybe im miss understanding how to use GWT i dont know.

    Any help would be appreciated

    Thanks

  • Primus
    Primus over 13 years
    Thanks guys for your quick replies. My beef with the dialogbox is it has no window frame nor the typical window look, url location etc.