#1541 Fantom doubts ..

pawansharma Thu 19 May 2011

Hi Fantom Team,

I am Java Developer since 6 years, and now using Fantom. As Fantom is very powerful language having similarity with Java. Here i have some doubt, Can you please give your valuable comments here.

(a) Can i call function of .Fan class in .fwt file ? If yes then how ? I tried to call Test() function from "Dummy.fan" in my "Demo.fwt" but getting following error.

Unknown slot sys::Dummy.Test

(b) in some examples fwt code is in .fwt file... in some example .fan class. Here i would like to know which approach is right ??

If i am developing Web Application where i need good UI and database connection then which approach is right ?? (a) Writing Code in ".fwt" (b) Writing code in ".fan" ?

(c) Is there any example having some web pages and database connectivity ??

(d) What should we use for Data Travel, I mean for Data Trasfer Objects ?

(e) I am using SkySpart also and read about Fresco. Is Fresco a framework ??

Sir, Please answer these silly questions, they will help me a lot for moving with Fantom.

Thanks, Pawan Sharma

DanielFath Thu 19 May 2011

A) You can't call any function that doesn't exist as a pod in that environment. By default the Fantom checks in {your_fantom_folder}/lib/fan to see if there is an appropriate pod there. If there isn't it will say that he couldn't find the pod. Until file is built (using fan build.fan) it can't be called. In Java terms .pod is the equivalent of a .jar and the classpath is set to {your_fantom_folder}/lib/fan.

For more information check out Hello world examples

B) .fwt files cannot be compiled from the console. In order to compile them you need to setup a special .fan file which will compile them. So in order to make your application work, you write it as .fan. So

js   := compile(scriptDir + `mount.fwt`)
...
Str compile(File file)
{
  input := CompilerInput.make
  input.podName   = file.basename
  input.summary   = ""
  input.version   = Version("0")
  input.log.level = LogLevel.err
  input.isScript  = true
  input.srcStr    = file.readAllStr
  input.srcStrLoc = Loc.makeFile(file)
  input.mode      = CompilerInputMode.str
  input.output    = CompilerOutputMode.js
  return Compiler(input).compile.js
}

As far as I can tell .fwt is only used for WebApps that are heavy on FWT (Fantom Widget Toolkit).

C)If I recall correctly there aren't any direct examples of database connectivity because that requires a DB to exist. However, there are few tests that test DB and there you can find some examples of it. They're located in {your_fantom_folder}/src/sql/test. Be warned though, without properly configured database those tests fail.

Personally if you like mybatis you could check out fanbatis which is Fantom wrapper over mybatis. There are also some nice examples in the screencast.

Login or Signup to reply.