home *** CD-ROM | disk | FTP | other *** search
- # $Id: Main.pl,v 1.1 1996/07/26 05:14:52 pedja Exp $
- # Main.pl: converted from the original Main.wos
- # The original file contains the following notice:
- #
- # You may freely copy, distribute and reuse the code in this example.
- # NeXT disclaims any warranty of any kind, expressed or implied, as to
- # its fitness for any particular use.
- #
- # Script files define variables and actions associated with a
- # component--usually a page, but sometimes just a part of a page.
- # When a WebObjects application is running, these script files
- # are used to initialize WOWebScriptComponentControllers. The component
- # controller "adopts" the variables and actions declared in the script.
- #
- # A WOWebScriptComponentController is transient.
- # It's created when an application receives a request for its
- # corresponding page, and it goes away when the application returns a
- # response. Later, when a user performs an action from the page, the
- # WOWebScriptComponentController is recreated to handle the user's
- # action.
- #
- # For example, when a user opens the URL for the Cyber Wind program, the
- # Cyber Wind application receives a request for the Main page.
- # A WOWebScriptComponentController is created and initialized with this file.
- # Upon its initialization, the awake method is invoked.
- #
- # WOF creates a response containing the dynamically generated HTML for the
- # Main page and then destroys the Main's WOWebScriptComponentController.
- # Before destroying the component controller, WOF stores any variables that
- # are declared persistent. (Main doesn't have any persistent variables, so
- # no state is preserved in this case.)
- #
- # When the user clicks in the Main page of CyberWind, on either the
- # "See surfshop info" or "Buy a new sailboard" hyperlink, Cyber Wind receives
- # a new request from the Main page. When Cyber Wind gets the request, it
- # recreates the WOWebScriptComponentController for Main, so the Main
- # component controller can handle the users action. When its recreated,
- # awake is called again.
- #
- # The awake method is a good place to create variables because it's
- # called exactly once for every transaction (for requesting the page, and
- # for processing an action originating in the page). As an alternative,
- # you can declare persistent variables. That way, WOF will automatically
- # save and restore them for you. However, if the application serves a
- # large number of clients and generates a lot of persistent state storage,
- # the application will become a hog.
- #
-
- package WO::CyberWind::Main;
- use WOPerl;
- @IVARS=qw(options option);
-
- sub awake {
- my $self=shift;
- # The options array must be present for WOF to be able to create the
- # HTML for the Main page, and it must be present when Main's
- # component controller identifies what hyperlink the user clicked.
- $self->{'options'}=["See surfshop information", "Buy a new sailboard"];
- }
-
- # This method is called when one of the hyperlinks is clicked.
- # The option object (repetition's item) lets you identify which of the
- # hyperlinks was clicked, "Surfshops" or "Buy."
- sub chooseOption
- {
- my $self=shift;
- # print "option: $self->{'option'}\n";
- if ($self->{'option'} eq $self->{'options'}->[0]) {
- return $WOApp->pageWithName("Surfshops");
- } elsif ($self->{'option'} eq $self->{'options'}->[1]) {
- return $WOApp->pageWithName("Buy");
- } else { return $self; }
- }
-
- 'WO::CyberWind::Main';
- # EOF
-