Scripting Helma |
Donnerstag, 15. August 2002
Adding Forums to our application
matthias
10:43h
Today you will learn, how to create new forums, and how to render a list of them on our start page. The first thing we need is a new prototype, for the forums. A prototype in Helma is represented by a new folder in our application folder. In our case this is: apps/forum In OOP language, this folder is the class which describes the properties and holds the methods. To declare new properties we will use the type.properties file and to create new methods, we will just add .hac files or functions() in .js files. So what does this mean for the non-programming-pro? In our forum application we want to be able to create new forums. But Helma, doesn't know what a forum is like, what it can do and what it can store. So we need to describe a prototype of this forum. You can imagine this as the production line, or form, that will produce our forums. (with the exception, that when we change something in our production line, it will also affect the already produced objects). To create a new prototype in Helma, we just add a folder to our application directory. We will call this folder "forum". The complete path is: apps/forum/forum . It has no meaning or relevance, that the application folder, and the folder for our first own prototype are named the same. create a main.hac file in the newly created folder. Open it in a text editor and type in: res.write("I'm a forum"); Now if open the URL http://localhost:8080/forum/forum/main in your browser: Nothing will happen!? That' because we just created the prototype of a forum, and not an actual forum (-object) itself. Adding and storing properties and objects The only object we have so far is the root object. The root object, is created as soon as we create our new application. We can use the root folder in our application directory to describe and script it, like we did this with our start page. And the root object is persistent! That means, when we add or change a property than it will be still there after we stop and restart Helma. To make another object, than root persistent we need to "add" it to an already persistent object. And at the beginning of an application this is the root object. Before we add new forums, we test how to add and change properties of root. So open the main.hac in root again, script the lines, and call it with the browser via http://localhost:8080/forum. This is just for testing! To add a new property, or change it we can say: this.propertyName="test"; this.header="My first Helma application";this is the keyword, which represents the object, we are using the dot is the sperator propertyName is same name for our property. This name can be any leagal JavaScript variable name. the equal sign says that the left part should become equal to the right part "test" is a string (that's why it is quoted), but can be also a Number, or any other JavaScript datatype or object. And it can be a HopObject, what we will see next. To call a property of an object we say: Creating forums and rendering the list The new code for root/main.hac is: var aNewForum = new forum(); this.add(aNewForum); for (var i=0; i<this.count(); i++) { res.write('<a href="'+this.get(i).href("main")+'"> Forum No.'+i+'</a><br>'); } // this.renderSkin("main"); Open the URL http://localhost:8080/forum in your browser and hit the reload button for a few times. If it doesn't work right from the start you maybe have to restart Helma. What you can see is a growing list of links to Forums. When you click on one of the links you will see: I'm a forum and when you take a look at the URL in your brwoser you will see something like: http://localhost:8080/forum/4/main Basically the few lines of code we wrote create a new forum each time we call root/main.hac, with a browser. After we created and added a new forum, we loop through all the existing forums and render a link to this forums. Here is a very detailed description of what is going on: Line1: Line2: Line4: Line5: Line6: Line8: Helma is scripted with JavsScript! To fully understand the code we will use in the rest of this tutorial you need to learn JavaScript or consider a book or online Tutorial about this. But even, if you are just familiar with an other programming language, like PHP, ASP, C++ or Java you should be able to read the code and follow the examples. The fact, that we are using JavaScript doesn't mean it's the same JavaScript like you are maybe used to from scripting in a HTML page. The main difference is, that there are no special ClientSide objects, like the window object, or document.all or stuff like this. But at least the syntax is the same. But there are a lot of other objects in exchange we will need on the server side. For example the res (response) or the req (request) object, and so on. Next time Next time we will learn how to control this behavior a little bit more :)
... Link |
Online for 8546 days
Last modified: 08.08.02, 10:22 Status
Youre not logged in ... Login
Menu
Suche
Calendar
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)
|