#433 Hello World web version

julien Sun 18 Jan 2009

Hi all,

Fan looks like a great language and I really like the direction it's taking. As a web developer (meaning this is my current job) I checked the Hello World example and got straight to the web version. Unfortunately, I cannot get it running.

First thing is a typo in the code on the HelloWorld page:

override Void doGet()
{
  res.headers["Content-Type"] = "text/plain"
  res.out.printLine("hello world #4")
}

The doGet() should be changed as onGet().

Second thing is a stacktrace:

julien@lbi-juhe-ubuntu:~/Fan$ ./bin/fan examples/web/hello.fan 
[15:27:24 18-Jan-09] [error] [fand] Error initializing script [/home/julien/Fan/examples/web/hello.fan]
sys::NullErr: Coerce to non-null
  fan.sys.NullErr.makeCoerce (NullErr.java:38)
  web::Weblet.make$ (Weblet.fan:26)
  hello_0::Hello.make$ (/home/julien/Fan/examples/web/hello.fan:36)
  hello_0::Hello.make (/home/julien/Fan/examples/web/hello.fan)
  hello_0::Boot.setup (/home/julien/Fan/examples/web/hello.fan:31)
  fand::BootScript.make$ (BootScript.fan:27)
  hello_0::Boot.make$ (/home/julien/Fan/examples/web/hello.fan:18)
  hello_0::Boot.make (/home/julien/Fan/examples/web/hello.fan)

The Weblet default constructor reads:

new make()
{
  req = (WebReq)Thread.locals["web.req"]
  res = (WebRes)Thread.locals["web.res"]
}

req and res are declared:

**
** The WebReq instance for this request.
**
@transient readonly WebReq req

**
** The WebRes instance for this request.
**
@transient readonly WebRes res

And thus non-nullable. It looks like res is set to null hence the stacktrace.

Still, I haven't read the full manual so maybe I've made a mistake somewhere. I've been browsing the forum and documentation but couldn't find anything to fix that.

Could somemone have a look at it?

Thanks a lot,

Julien

PS: Maybe it's time to open a second forum where lambda users can post that kind of requests. After reading the topics, I don't feel this should be posted here but I haven't found any other place.

brian Sun 18 Jan 2009

Julien,

I am very sorry about that. I noticed there was a bug in the example right after I did the last build. I pushed a fix to Mercurial for the next build.

In the meantime, there is a simple fix to the "examples/web/hello.fan" script

override Void setup()
{
  // change from Hello() ctor to Hello# type literal
  Sys.ns.create(`/homePage`, Hello#)  
}

I just verified that and it should work, if not let me know.

Good catch on the docs also, I will push a fix for that.

Brian

julien Sun 18 Jan 2009

Brian,

It's working fine. Thank you!

Login or Signup to reply.