« [Tip] Calculate Age | Main | [Tip] inline Servoy Sample Code »

September 29, 2004

[Tutorial] Forms, Elements and Methods Overview

by Marcel Trapman
www.it2be.com

Ok, here you are, you are developing your very first Servoy (test) application and you get stuck because of those tiny little things you don't know of.

With this little article I take a shot at helping you to understand some things about forms, elements and methods. Not a complete tutorial and not a complete reference at all. My only goal here is to help you developing your solutions with Servoy.

Forms:

  • are the basis for your solutions window
  • are based on one table of your database(s)
  • can contain all kinds of elements
  • can contain methods
When creating a form you can give it a name. Please make this name as logical as possible to your benefit when your solutions grows. After creating the form you will notice you will have lots of properties you can edit. This is not going the be the place where all possible question are going to be adressed. However, having that said I feel the need to talk about some of them:

  • titleText: can be used to set the title of a window, combined with tags %%tag%% and i18n very powerfull
  • onXXX: these properties can be set to attach a method to the named event or 'menu' choice. In case you attach a method to a 'menu' choice you replace the 'standard' functionality with your custom functionality
  • view: there are 3 possible views, record-, list- and table-view. The first two can be viewed in normal mode, giving the user the possibility to switch between views. Little downside of these views is a 'margin' on the left, needed to show the location of the record in the table. However, when you lock the view, user-switching of the view is not possible anymore and the 'margins' are gone.
  • a reference to a form could look like forms.formname
Elements:

  • in some environments known as objects
  • field elements can be chosen when creating a new form
  • all elements can be chosen from the menu and placed everywhere on the form
  • fields can be changed into comboboxes, htmlfields etc (holding a reference to the dataprovider (column/field) of the table of the form or a related dataprovider) via the displayType property
  • the tab sequence of elements can be set via the tabSeq property
  • can be labels, graphical elements, beans etc.
The manuals are a good reference to what and how you can work with all elements. The things I do want to bring to your attention are:

  • the name property: by setting the name property of an element you are able to individually set the properties of the element via a method
  • element properties and functions can be set/called from within a form like 'elements.elementname.property' or from other forms or global methods in the following manner: 'forms.formname.elements.elementname.property' (there are more dynamic methods but again these go beyond the scope of this article)
  • readOnly: elements can, individually, be set to be 'read only'. However there is also a form/controller property named controller.readOnly. By using this property you set all elements that have the readOnly property. Please bare in mind that by using this controller property you also set this property for possible tabpanels/forms on the form you call the controller from
  • enabled: see the above
Methods:

  • aka scripts or maybe classes
  • contain code (javascript) that has to be executed
  • can be global, attached to (events of a) form or attached to (events of) elements
The tutorial 'Intro to Methods' (written by Bob Cusick and Jan Aleman) should get you going with the basics. All I want to say for now is:

When you write a method to, let's say, add a new record, and you use more than one form on the same table, and you want to be able to add that record from within all those forms, you don't want to write that piece of code over and over. You want to reuse that code! Well, that's very well possible by thinking about what I showed you in the examples above. It is also possible to call a method from outside the form.

In this case you would create a method newRecord (or whatever name) on every form and attach them to the wanted button. Now, think of one of the forms as your main form and fill the method on that form with the desired javascript. All other methods should contain only a reference to that method. The reference would look like: 'forms.mainform.newRecord()'. This way, by pressing a button on a subform you will call the desired method on the main form. The beauty is that you only make the same mistakes once ;-)

I hope this article helped you in some way.

Cheers
Marcel

| Posted by IT2Be on September 29, 2004 at 12:23 PM in Tutorials | Permalink

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c8d8153ef00d8344e915c53ef

Listed below are links to weblogs that reference [Tutorial] Forms, Elements and Methods Overview:

Comments

Great site, well done.
I enjoy beeing here and i´ll come back soon.
You do a great job. Many greetings.

Posted by: Tammy | Jun 15, 2005 10:10:57 AM

Post a comment