views:

387

answers:

2

Hi, We have a large GWT project and many smaller GWT sub-projects basically the large controller project invokes the smaller projects via many means such as some are incorporated into iframes that are shown in page, some are shown by clicking a URL and opening the project into a new window.

The requirement is to change the Css on the fly, this is possible in the main project, by simply changing, on the fly, the href of the link tag containing stylesheet url

is it possible to propogate this change to the sub-projects too ? or asking in more broader terms, how do i achieve inter - project communication in GWT ?

+2  A: 

A browse allows you to call Javascript code across IFrames if the domains of the different GWT applications are the same.

Using JSNI you can register methods on the window object which call back into the GWT application and using JSNI the other project can invoke this method.

David Nouls
<pre>good solution, working on it.I have achieved one thing, the parent can initially notify the child via url parameters since it is indeed loading it in iframes.However, for refreshing/change notification, i am thinking of implementing your approach.+1 for this great solution</pre>
Salvin Francis
Hey the jsni approach is failing in one senario, Different window. i have a login module that, on success changes the page url to another gwt module. in this case the javascript global variable value is lost [makes sense since the window itself has changed, then window.variable is no longer in scope], what should i do in this case ? use a cookie ?
Salvin Francis
The main frame could listen to reload events and re-register the callback. the client could put a method available when loaded, that the main frame can call into. There are plenty of options.
David Nouls
+1  A: 

If all the apps are served from the same domain you could store the name of the stylesheet in a cookie. Each app would then use the cookie to select the appropriate stylesheet.

String theme = Cookies.getCookie("THEME");
if (theme == null) {
    theme = "default";
}

Element e = DOM.createElement("link");
DOM.setElementProperty(e, "rel", "stylesheet");
DOM.setElementProperty(e, "href", GWT.getModuleBaseURL() + currentTheme + 
    ".css");
DOM.appendChild(getHead(), e);

private native Element getHead() /*-{
    return $doc.getElementsByTagName('head')[0];
}-*/;
David Tinker
hi, i feel you have misinterpreted the Question, Cookies are a great way to store something common, but my problem here is invoking, the parent should invoke/notify the child to change its Css to something else.Still good suggestion so, +1
Salvin Francis