« [Tip] Avoiding related searches "ghost" records | Main | [Documentation] Servoy 2.2 Documentation Now Available »

June 25, 2005

[Tip] Setting up a method repository

Screen_1Sometimes you may have the need to put lots of buttons on a form.
Even if Servoy lets you easily add elements to a form, you can quickly remain short of space.
To solve the problem, I thought that the best way to do it was to create a form based on a dedicated table storing all the method's references and to show the form in list view inside a tabpanel placed on the original form (where the original buttons were placed).
Since I wanted to keep it simple, I put four fields on the table:
methodid (pk)
description (the visible name of the method: the only one seen by the user)
method_name: the full name of the method,  (e.g. "forms.reports.invoices_monthly();", without quotes)
sorter (an integer field useful if you want to sort items the way you want: it contains a user-definable sequence of number )

After that, I created the form (I called it query_repository)
Now, since the form is shown in list view, I needed to find a way to link each row to a different method.
My first thought was to build a "general purpose" method based on a CASE... structure, but I didn't like this option (the resulting script was very long and, when I'm responsible for the debugging, I prefer to deal with concise scripts). So, I decided to try with eval function.
Result: one line of code the manage a dozen of methods!
Every row of query_repository, when clicked, invokes the method "launch_method" containing the instruction:
eval(method_name)

This way, I can link a different method to every row I create, simply writing the method's full name into the right field: quick and easy.

Better still: you can use html instead of a button to launch the method, linking it with "a href=" tag; to do that, you have to format the field description to html area: the main advantages are that you don't need to put a button or set the field to execute the method anymore (user can simply click on the method name the way they do with html pages links) and, if you want to group methods under categories, you can always format the html content of description field to show a row like a header (see picture), with no methods linked into the html.

| Posted by Riccardo Albieri on June 25, 2005 at 11:59 AM in Tips | Permalink

Comments

Post a comment