Is there an article or documentation somewhere discussing the concept of the currentcontroller. I’m actually using the currentcontroller here and there, but I feel wobbly about when and where to use it, what it does for me, when to avoid it, in contrast to the forms.xxx.controller. The official Servoy docs on the subject are a might thin.
Several of my screen presentations are made up of a form comprising two tabpanels and a custom controller form. One of the tabpanels is in record view, the other in table. From painful experience I’ve learned to make these tabpanels relationless.
On the theory that forms hold records independently, I’ve been loading records into both the record and the table tabpanel forms. Yet I’ve also been discovering if I forget to load the table form, it’s properly loaded anyway. I need to know why this is.
Another puzzle. Given the screen structure described above, should I be using currentcontroller.loadRecords() instead of forms.xxx.loadRecords()? I’m currently using the latter.
After writing the above I did some further experimenting. I’ve discovered that I do indeed need to load both tabpanel forms when the set of records is not ALL records. Also that running currentcontroller.loadRecords(relationship) from a method based on the custom controller will NOT work. So I’m indeed puzzled about the do’s and don’ts of the customcontroller.
As I said, a wobbly understanding. By the way, my forms are working although possibly not efficiently constructed.
CurrentController works on the PARENT table. In your example of having a form (let’s say based on the “customer” table) with two tabpanels - if you said:
currentcontroller.newRecord()
You would create a new CUSTOMER record. You can then use that same method when you were viewing an invoice to create a new INVOICE record (not the related children).
IF you did not use currentcontroller - then you would have to write a method that explicitly “touched” the controller of each form:
forms.customer.controller.newRecord()
and
forms.invoices.controller.newRecord()
Loading records. If you are displaying two different forms in two different tabpanels - but they are based on the same TABLE - then their foundsets are LINKED TOGETHER. So, doing a find (or loadRecords) in ONE will show the correct record in the other automatically. If you want to show DIFFERENT records in either tabpanel (i.e. UNLINK the found sets) then check the box “useSeparateFoundSets” on the FORM level.
bcusick:
2. Loading records. If you are displaying two different forms in two different tabpanels - but they are based on the same TABLE - then their foundsets are LINKED TOGETHER. So, doing a find (or loadRecords) in ONE will show the correct record in the other automatically. If you want to show DIFFERENT records in either tabpanel (i.e. UNLINK the found sets) then check the box “useSeparateFoundSets” on the FORM level.
The above has not been my experience. My form has two tabpanels, both related to the same table, neither bound to a relationship.
What you say is true when all records are loaded. However, I have a search popup on the custom controller which looks for clients, customers, suppliers, etc. These programmed searches appear to need to be loaded into each of the two tabpanels, not via currentcontroller.loadRecords(). There may well be other factors at play here. Thus my confusion about when and where to utilize the currentcontroller functions.
This only happens (in my experience) when you load records yourself (“programmed searches”?).
If you use something like controller.loadRecords foundsets “tend” (haven’t done thorough testing) to get out of synch and you will have to take care of them yourself. Expected bahaviour is, however, when you do controller.loadAllRecords, your two forms will be synched again.
I’ve gone through exactly the same confusion of “What’s going on here?” My setup is exactly the same as Patrick’s – a non-relational tabpanel with a record and a table form which I want to keep co-ordinated at all times.
In my custom controller I’ve placed some programmed popups to do searches. If unsuccessful, then I want a rollback for both forms to their previous state. When the two forms fell out of sync I stopped relying on Servoy to do the co-ordination. Now I load both forms whenever a change in status occurs.
Thus my original question about the role of the currentcontroller function. Thanks for the heads up.
and are you positive that you’re two forms are in synch after you manually load records (the ones you saved before)? My impression was that that doesn’t work quite right. At least I decided to not offer my users that feature of restoring their original foundset.