Name the divs calc1, calc2, calc3, etc. Then in the GWT app use a for loop
(RootPanel r = RootPanel.get("calc" + i) ). You can either keep going until
you get a null (i.e. not found - but if you miss an id in the sequence then
you'll stop before you have found them all) or loop through until you feel
'this is getting pointless'  (i.e. keep looping until you reach a million or
two).
Or you could use a custom attribute <div addcalc=true></div> get all the div
elements and check each one for the element.

You can't use <div addcalc></div> and use if(addcald != null) because GWT in
it's infinite wisdom will set missing attributes to an empty string even if
it is missing (browsers don't do this in JS, they return null if it's
missing), so you cant tell if it is there with no value set, or whether it
it is not there at all.

Or you can use a custom tag - e.g. <div><calc></calc></div> and repace every
'calc' tag.

Ian

http://examples.roughian.com


2009/7/8 vduong <[email protected]>

>
> Any suggestions if we want to include the same widget more than once
> in the page? (e.g. two calculators on one html page)
>
> On Jul 7, 11:00 am, Ian Bambury <[email protected]> wrote:
> > Hi,
> >
> > 'Embed' isn't actually going to find you the right info, unfortunately.
> Or
> > at least, not much. What you need to know is how GWT works.
> >
> > For something like this, you need to have your GWT app add your Calc
> widget
> > to a div in the html page.
> >
> > A simple way to do this is to put a <div id=calc></div> in your html page
> > and also include the gwt script (i.e. the one referencing the nocache js
> > file).
> > In the GWT app, have the onModuleLoad method do a
> > RootPanel.get("calc").add(new MyCalc());
> >
> > This is unsafe inasmuch as if the element with the id is missing, you'll
> get
> > an error.
> >
> > You could check if the element with the id is there and if it is, add a
> > calculator. In this way, you could have your app insert widgets if it
> finds
> > the right id, so one app could be reused if pages need, say, a
> calculator, a
> > stockticker, or both (and not crash if it needs neither).
> >
> > If you need more info, just yell.
> >
> > Ian
> >
> > http://examples.roughian.com
> >
> > 2009/7/7 Arne Schroeder <[email protected]>
> >
> >
> >
> >
> >
> > > Hi all,
> > > searching this group for "embed" I found several examples how to embed
> > > Flex/Flash/Webapplications into GWT, but no simple thing like
> > > embedding GWT widgets in a pure HTML page (maybe combined with extra
> > > javascript).
> >
> > > I have just started using GWT. I built a very simple calculator widget
> > > from a few buttons and a text field, which runs fine as a web
> > > application. This calculator needs no client-server communication, so
> > > that I believe I should be able to copy the generated js files and
> > > helper files to the right places and thus embed the calculator in
> > > other webpages.
> >
> > > Can I find such a description somewhere, how to use the compiled GWT
> > > output as custom javascript widgets?
> >
> > > Thank you
> > > Arne
> >
>

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

Reply via email to