This Question is Answered

7 "helpful" answers available (3 pts)
14 Replies Last post: Jun 19, 2008 9:50 PM by tiju

sub-applets

Jun 17, 2008 1:58 AM

Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
Hi all,

Long time I have been bogged down by jiras. Now I have started working on creating sub-applets from inside parent applets. Having gone through the shape example provided in the dguide, I need some help from the experts.

How do we suspend a current applet assume a parent applet before being taken to a sub-applet? If we get the AppletData object of the current applet, I believe calling the suspend on that object should do the trick. But then how to get the AppletData object of a current applet?
Click to view cbarber's profile Curl cbarber 124 posts since
Sep 27, 2007
1. Re: sub-applets Jun 17, 2008 5:40 AM
I don't believe there is an API for suspending the current applet. You could browse to another page from within that applet using browse-url, but why do you want to suspend the parent applet in any case? Can you explain your scenario a little more?
Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
2. Re: sub-applets Jun 17, 2008 6:11 AM
in response to: cbarber
I think I got myself wrong.

I wanted to use the sub-applet functionality from a parent applet at the same time freeze any activity on my parent applet. After that, I needed to exit out of the sub-applet through a button-click to return back to my parent applet retaining any information collapsed/expanded/scrolled up-down/scrolled left-right as it was when I navigated to the sub-applet.

I have just seen that simply the {{get-the-applet}.browse-url “../another-applet/start.curl”} could do the trick and to navigate back, we can use the browser back button.

Hope we cannot browse to a dcurl and make the parent applet frozen, or then, the word "detached" applet would render meaningless, right?
Click to view wbardwell's profile Curl wbardwell 75 posts since
Oct 31, 2007
3. Re: sub-applets Jun 17, 2008 9:35 AM
in response to: tiju

Sub-applets are hosted by the parent applet, so the parent applet can not be suspended while the sub-applet is running. The parent applet can just be in the event loop though.


You can use browse-url for non-detached applets to go to another applet, and as long as the machine doesn't run low on memory, you can browse back to the original applet

with the browser back button or by calling Applet.browse-backward.


But detached applets don't have a browser, so for them you would just leave the parent applet running.


Why do you want to freeze the parent applet?

Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
4. Re: sub-applets Jun 17, 2008 9:45 PM
in response to: wbardwell
Thanks Bardwell, these are important information for me.

Having different applet projects, I am trying to implement drilldown from an applet to a another applet as a sub-applet or otherwise. I wanted the user not to edit the parent applet when he/she has drilled down to the sub-applet.

Probably, I might have to use the browse-url going through your help, but then I am concerned about the memory accumulation as the user might have to take any number of sub-applets as I want to provide the drill-down functionality for the sub-applet too.
Click to view Duke's profile Curl Duke 179 posts since
Oct 17, 2007
5. Re: sub-applets Jun 17, 2008 10:59 PM
in response to: tiju
What is it about the drill down that requires the use of separate applets? Can you combine the functions into one applet? A potential problem with using separate applets and using browser page navigation to move back and forth between them is that if memory is running low, then some of the earlier suspended applets (not visible currently in the browser) may be purged. To handle that case, you will need to use register-exit-proc and maybe register-suspend-proc to store the state of the purged applet, so that the applet's state can be restored if you visit the applet again.
Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
6. Re: sub-applets Jun 17, 2008 11:38 PM
in response to: Duke
If I am to combine the applets, I will have to code the sub-applet (which are presently projects) afresh.

Going by your comments, I feel I will have to use the register-exit-proc and the register-suspend-proc to store the state of old applets, so that the applet's state can be restored once I go back to the initial applet.

Are there any code samples available that use the register-exit-proc and the register-suspend-proc?
Click to view Duke's profile Curl Duke 179 posts since
Oct 17, 2007
7. Re: sub-applets Jun 18, 2008 5:39 PM
in response to: tiju
The documentation about persistent data has a section near its end about saving it when the applet is suspended or exited. Here is a little piece of code.

{curl 6.0 applet}

|| Use a repository to show how many times this applet has been loaded.

||Define the parameters for the default repository
{persistent-data
    "saved values",
    duration=180days
}

{def tf = {TextField}}

{try
    || Be prepared to catch an exception if repository
    || has not yet been created.

    || Get the value from the repository
    set tf.value = {get-persistent-data "tf value"}

 catch not-found:KeyNotFoundException do
    || The key was not found, so the value has not been stored
    || before.
}


{define-proc {save-on-exit}:void
    || Update the value in the repository
    {set-persistent-data "tf value", tf.value}
    {commit-persistent-data}
}

{register-exit-proc save-on-exit}

{value tf}
Click to view Duke's profile Curl Duke 179 posts since
Oct 17, 2007
8. Re: sub-applets Jun 18, 2008 6:49 PM
in response to: Duke
I forgot to add that you can test this action when the applet is purged by using the Curl RTE Control Panel > Show Applets, which will give you a command to purge suspended applets. So browse away from an applet, which will suspend it, then you can use the dialog to purge it.
Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
9. Re: sub-applets Jun 18, 2008 11:54 PM
in response to: Duke
Thanks Duke. But then, I need to store the state of a complex UI which has been built up after parsing an xml from server. Is there any other alternative than to use the persistance?
Click to view rhh's profile Curl rhh 29 posts since
Oct 12, 2007
10. Re: sub-applets Jun 19, 2008 9:04 AM
in response to: tiju
I understand that you started in a certain direction involving subapplets and you don't want to change your direction now, but based on what I have read in this thread, it really seems to me that using subapplets is the hard way to do what you want, and it would be much easier to do it in one applet. I haven't yet seen any requirement mentioned in this thread that requires or benefits from using a subapplet.

There really aren't many cases where using subapplets is an easier way to solve a problem than just using one applet, but generally the cases that we know about fall into a couple of categories:

  • You want to do a lengthy computation and you don't want your applet's user interface to freeze up while the lengthy computation is happening. In such a case, it can be useful to create a subapplet, serialize the computation's input parameters and send them to the subapplet, and finally serialize the computation's result and send that back to the parent applet. This could be useful either for implementing a lengthy computation directly on the client, or in a situation where you need to access a resource elsewhere on the network and the resource may be slow to respond.
  • You want to load code from an untrusted source on the Internet and you want to carefully isolate the sandbox in which that code executes from the rest of your application.

Honestly, I think that using subapplets for purposes other than these is likely to make your life more difficult, not easier.

-Bert
Click to view Duke's profile Curl Duke 179 posts since
Oct 17, 2007
11. Re: sub-applets Jun 19, 2008 10:32 AM
in response to: tiju
You can use request-local-data-permission to use local disk file storage in a sandbox. OCC applets use that. There is also some work being done with SQLite databases for the 7.0 release, if that might be useful.

But I think you can actually save a good bit of state in the persistent data repositories, even for an unprivileged applet.

Applets that are not privileged have these restrictions on their persistent data storage:
* An applet is limited to opening 20 data repositories.
* The data repositories are each limited to 256K bytes.
Click to view cbarber's profile Curl cbarber 124 posts since
Sep 27, 2007
12. Re: sub-applets Jun 19, 2008 1:01 PM
in response to: rhh
Some other scenarios where subapplets are useful include:

  • To take advantage of multiple processors or hyperthreading on more powerful client machines
  • Run code using multiple versions of Curl (e.g. to support mashups or cross-version component testing)
  • In test frameworks to allow subapplet to be debugged without freezing up test-driver controls
Click to view rhh's profile Curl rhh 29 posts since
Oct 12, 2007
13. Re: sub-applets Jun 19, 2008 1:11 PM
in response to: cbarber
Those are good additions to my list. Thanks!

-Bert
Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
14. Re: sub-applets Jun 19, 2008 9:50 PM
in response to: rhh
Thanks Bert for the valuable directions on this. It is really helpful. Let me rethink on my requirement and I will defenetely need further helps moving along.

Thanks Christopher and Duke for the help.