views:

39

answers:

1

Hi,
My GWT module UI is only single button (like AddThis/ShareThis Sharing Button), and all other stuff is done in JS Popup panels. Id is specified as Global JS variable (i.e. myConfig.id=22) and getting that Id in GWT module using JSNI method ($wnd.myConfig.id).

NOTE: There is also another way pass parameter, which is by setting

<div id='gwtRootPanel' alt='6323'> </div>
<script type="text/javascript" language="javascript" src="com.test.gwt.Common/com.test.gwt.Common.nocache.js"></script>

& in GWT code

RootPanel rootPanel = RootPanel.get("gwtRootPanel");
System.out.println("Passed Value " + DOM.getElementAttribute(rootPanel.getElement(), "alt"));

Both way works fine for only 1 button in page, Now I dont see any of this option feasible for adding multiple buttons (like same Share button for each blog in Blog Post list) in one HTML page..

If Using 1st way,
How to get different values for same GWT compiled file?

If using 2nd way,
Cannot use same < div id='gwtRootPanel' >...

Any Hint or solution?

Cheers,
Nachiket

+1  A: 

It's probably not a good idea to use multiple entry points on the same page. Instead use a single entry point and place markers on your page where you want it to interact.

So if you want to stick a GWT button widget within certain divs, you might implement your html like this:

<div id="marker1"></div>
<!-- more stuff -->
<div id="marker2"></div>
<!-- etc. -->

Then the entry point to your single GWT app would insert its own buttons from a loop like this:

public void onModuleLoad() {
  int i = 1;
  do {
    String id = "marker" + i;
    RootPanel rp = RootPanel.get(id);
    if (rp == null) {
      break;
    }
    rp.add(new MyWidget(getContextData(id)));
    i++;
  } while (true);
}

native String getContextData(String id) /*-{
  return $wnd.myConfig[id];
}-*/;

So this example would iterate through the html looking for matching ids and then insert widgets as child elements there. Additionally it uses the id as a context to get some more data which is in the page.

locka
Nachiket