Scripting Helma
Montag, 12. August 2002
Scripting a simple Forum

In this chapter we will script our first real Helma web application. - a small forum. You will learn how to create HopObject classes and connect them to a database (mySQL). Even if you never scripted a web application before, and have no idea about SQL, HTTP-headers and so on you should be able to understand this example. If not: kick me.

Create a new application
start Helma and create a new application called "forum" via the apps.properties file, like described in the "Hello World" example

Making the start screen
First we will create a start screen for our forum application. All we want is a header, a list of all existing forums and a button (link) to create a new forum.

With our existing knowledge we create a main.hac in root. Instead of

res.write("Hello World!");
we would start with something like:

res.write("<html>");
res.write("<head>");
res.write("<title> My first Helma application</title>");
res.write("</head>");</p><p>res.write("<body>");
res.write("<h2>My first Helma application</h2>");
res.write("<h4>existing discussion boards:</h4>");
....
But all this res.write's are getting boring. So we need a solution for this. If you know PHP or ASP, you would propably start using a syntax like this:
<% some code %>

<html>
<head>
<title> My first Helma application</title>
</head>
....
<% some more code %>

But Helma won't allow this in .hac files. So what can we do to solve this?

What you need are "Skins".

A Skin is a template, which can be called by a function. But before we learn more about skins and hac's in detail, lets solve our start page:

First create a file called "main.skin" in root. (The name "main" has no special meaning with .skin files) Open it in a text editor and script the following simple HTML page:
<html>
<head>
<title> My first Helma application </title>
</head></p><p><body>
<h2>My first Helma application</h2>
<h4>exisiting message boards:</h4>
// here goes the list
<br>
<a href="addForum">neues Forum anlegen</a><br>
<br></p><p></body>
</html>

Then open root/main.hac and script:

root.renderSkin("main");

When you open http://localhost:8080/forum you should see the HTML page.

So why do I need "Skins"?

Helma has a very strict, but clean way to sepperate logic from presentation. It doesn't allow you to have logic in .skin files and makes it very hard to have presentation (HTML in our case) in functions or .hac files. (just see our res.write, res.write example). This may seem complicated in the beginning. But it is just a disadvantage, as long as your apps don't have mor than 10 lines of code. For bigger applications it reduces the risk of bugs and makes it possible to let the HTML guys take care about the HTML, without doing too big damage. It is possible to store skins in a database and make them editable by others than the programmers, like Antville demonstrates.

Note: This should go somewhere else
A .hac file is just a function on the server which can be called via an URL. A function is peace of code which contains the logic of our application and manages what happens when we call a page. For people who are more familiar with OOP, a function in Helma is a method of the HopObject class where it is located. In this case this is the root class. Each folder in the apps directory represents a HopObject class. (Except global). As this example continues things will become more clear.

Lets have look at our root/main.hac:

root.renderSkin("main");
root is a global identifier for the root HopObject.
renderSkin is a HopObject method (function) which renders the specified skin for that object
"main" is a string, which is an argument for the function. It specifies the name of the skin (file).

The "dot"-syntax mainly says:
call the function renderSkin on root, and use the parameter "main".

next time we will learn how to write macros. (what's that?!?!)

Online for 8337 days
Last modified: 08.08.02, 10:22
Status
Youre not logged in ... Login
Menu
... Home
... Tags

Suche
Calendar
April 2024
So.Mo.Di.Mi.Do.Fr.Sa.
123456
78910111213
14151617181920
21222324252627
282930
November
Recent updates
Controlling the form behaviour Last
time our application was able to create forums, but in...
by matthias (15.11.02, 20:04)
Scripting a simple Forum In
this chapter we will script our first real Helma web...
by matthias (15.11.02, 18:37)
Adding Forums to our application
Today you will learn, how to create new forums, and...
by matthias (15.08.02, 12:27)
Hello World After we succesfully
installed Helma, we will write our first application: The traditional...
by matthias (11.08.02, 13:32)
Installing Helma Helma is 100%
Java, that means, that you can run it on a...
by matthias (08.08.02, 20:32)
How to script Helma ....
That's what you would love to know. .... RIGHT! Antville...
by matthias (06.08.02, 12:00)
How can you get involved?
Helma.org is providing a lot of gates which you can...
by matthias (06.08.02, 11:48)
first try funny, an hour
ago i first saw this tool, because i was testing...
by matthias (28.06.01, 17:20)

RSS feed

Made with Antville
Helma Object Publisher