it seems that it is not possible to write iframe's content directly in
html.
you can add it programatically which seems even more convenient (but i
wanted to avoid it do to some inconsistency between browser as to when
cotnentDocument of an iframe becames available to code - there can
happen some delay in some browser and onload event is called event if
this iframe does not load any remote content.)
so with this precaution here's the code:


    static class YourChart extends Widget {

        private static final String API_URL = "http://ajax.googleapis.com/
ajax/static/modules/gviz/1.0/chart.js";
                private HandlerRegistration handlerRegistration;

        public YourChart(JSONObject userConf) {
            this(userConf.toString());
        }

        public YourChart(final String userConf) {
            final IFrameElement elem =
Document.get().createIFrameElement();

            setElement(elem);

            if(elem.getContentDocument() == null ||
                        elem.getContentDocument().getBody() == null){

                handlerRegistration = addDomHandler(new LoadHandler(){

                                @Override
                                public void onLoad(LoadEvent event) {
                                        initFrame(elem, userConf);
                                }

                }, LoadEvent.getType());
            }
            else {
                initFrame(elem, userConf);
            }
        }

                private void initFrame(IFrameElement elem, String userConf) {
                        if(handlerRegistration != null){
                                handlerRegistration.removeHandler();
                                handlerRegistration = null;
                        }
            Document cDoc = elem.getContentDocument();
            BodyElement body = cDoc.getBody();
            ScriptElement script = cDoc.createScriptElement(API_URL);
            script.setInnerText(userConf);
            body.appendChild(script);
                }
    }

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to