#2801 Fantom Dom Help: Some of us still beginners

small_petit Mon 22 Jun 2020

Having done some tutorials on HTML DOM interface, I decided to practice same in Fantom. But I get the error sys::UnknownTypeErr: dom::WinPeer.

Please this is my code:


Void onIndex() {
  res.headers["Content-Type"] = "text/html; charset=utf-8"
  out := res.out

    doc := Win.cur.doc 
    doc.elemById("demo").text= "Hello World"

I have added the dom pod to my build.fan file.

Please any help? Thank you.

SlimerDude Mon 22 Jun 2020

Hi small_petit,

There's a lot more going on that you need to be aware of.

The lines:

doc := Win.cur.doc 
doc.elemById("demo").text= "Hello World"

Will only run in a Javascript environment, so they need to be compiled into a Javascript file, and that file needs to be served to the browser - where it can run.

You also need to serve up javascript files that represent other dependent Fantom pods, like dom, graphics, and sys - and don't forget the TimeZone database needed for logging!

So there's a lot more web server work that needs to be done just to get those 2 little lines to run in a browser.

I would look at this domkit example as a quick start project and see if that helps any.

I have written a suite of libraries that vastly simplify the process, namely the BedSheet app server and the Duvet library - but I am reticent to recommend these to you as I feel that, for your current level, they may just confuse and hinder rather than help.

small_petit Mon 22 Jun 2020

I get the idea SlimerDude. Indeed there's a lot of work to be done in those two lines of code.

I have been doing some web tutorials with your BedSheet library.

Sometimes my fear with third-party libraries is that when you stop developing it for whatever reasons (I hope it doesn't come to that), users may not be able to use the library again.

I have been following your tutorials on the alien factory site. Thank you for all the help you are offering. I have really learnt a lot from there. Kindly give us more, especially beginners.

More so, I used the Slim library for rendering some pages. It seems a little slow. That's why I decided to use the core Fantom library, not knowing so many things are hidden....

I am grateful for the time you have for all my queries. Regards.

Login or Signup to reply.