SlideShare uma empresa Scribd logo
1 de 49
Baixar para ler offline
Programming with
     Seaside

Alexandre Bergel
Alexandre.Bergel@cs.tcd.ie

LERO & DSG
Trinity College Dublin, Ireland



                                  1
Part I:
Seaside in a Nutshell
Outline

 1.   What is Seaside?
 2.   Starting Seaside
 3.   Create new Seaside Component
 4.   Creating GUI
 5.   Using CSS
 6.   Interaction Between Components




                          3
Alexandre Bergel
Introduction to Seaside

     Application server Framework
 •
     Useful for generating dynamic web pages
 •


     Web server application for Squeak (used in this
 •
     presentation) and VisualWorks.
     Works on the top of a webserver (Comanche,
 •
     Swazoo).
     Provides high-level API to handle navigation between
 •
     pages (links) and GUI.



Alexandre Bergel             4
Some of the Seaside Features

     Sessions as continuous piece of code
 •
     XHTML/CSS building
 •
     Callback based event-model
 •
     Composition and Reuse
 •
     Development tools
 •
     Interactive debugging
 •
     Multiple control flow
 •




Alexandre Bergel             5
Starting Seaside

     Start the server with:
 •
     WAKom startOn: 9090
     Go to to access the counter component:
 •
     http://localhost:9090/seaside/counter




Alexandre Bergel                 6
Component Responsibilities

     It is a subclass of WAComponent
 •
     It contains a State modeled as instance variables
 •
     The flow is defined by methods
 •
     Rendering (high-level API that generate XHTML)
 •
     Style (CSS)
 •




Alexandre Bergel              7
Counter Example
                                                           WAComponent

     WACounter inherits from WAComponent.
 •
                                                              WACounter
                                                          count
     self session registerObjectForBacktracking: self.
                                                         initialize
     count := 0
                                    count := count + 1   increase

                                    count := count - 1   decrease

html heading: count.
                                                         renderContentOn: html
html anchorWithAction: [self increase] text: '++'.
html space.
html anchorWithAction: [self decrease] text: '--'.

 WACounter class>>initialize
    self registerAsApplication: ‘counter’
Alexandre Bergel                            8
Creating new Component

     Designing a small application to memorize words in
 •
     a foreign language.
     Display a score to show the progress.
 •
     2 ways of using:
 •
     – Adding a new word in the database
     – Entering a translation




Alexandre Bergel               9
Creating new Component




Alexandre Bergel   10
Component Definition

     Definition of the main class:
 •
     WAComponent subclass: #Learner
     	instanceVariableNames: 'words germanWord englishWord
     score'
     	classVariableNames: ''
     	poolDictionaries: ''
     	category: 'WordLearning'




Alexandre Bergel             11
Variables Initialization

     List of entered words:
 •
     Learner>>words
     	words ifNil: [words := OrderedCollection new].
     	^ words
     Score (increased when an entered word is correct):
 •
     Learner>>score
     	score ifNil: [score := 0].
     	^ score
     Choose a word:
 •
     Learner>>chooseEntry
     	 ^ self words atRandom




Alexandre Bergel                   12
Helper Methods

     Could we ask for a word?
 •
     Learner>>readyToGuessWord
     	^ self words notEmpty
     Increasing the score:
 •
     Learner>> increaseScore
     	score := self score + 1




Alexandre Bergel                13
Managing the Back Button

     Need to keep the history of the objects, in case of
 •
     pressing the back button on the web browser
     Learner>>initialize
     	super initialize.
     	self session registerObjectForBacktracking: self.

     A trace of the lifetime is kept. When the back button
 •
     is pressed, state previously recorded is restored.




Alexandre Bergel                 14
Registration of the Application

     Application registration:
 •
     Learner class>>initialize
     	self registerAsApplication: 'word'




Alexandre Bergel                 15
Rendering (1/2)

     Learner>>renderContentOn: html
 •
      html heading: 'Improve your Language Skills'.
      html form: [
        html text: 'English: '.
      	html textInputWithCallback: [:w| englishWord := w].
      	html text: ' German: '.
      	html textInputWithCallback: [:w| germanWord := w].
      	html submitButtonWithAction:
      	 [self words add: (Array with: englishWord with: germanWord)]
      	      text: 'Add Word'.
      ].
      ...


Alexandre Bergel
Rendering (2/2)

     ...
 •
      html horizontalRule.
      self readyToChooseWord ifTrue: [
      	html heading: 'Your score is: ', self score asString.
      	html form: [ |chosenWord|
      	 chosenWord := self chooseEntry.
      	 html text: (chosenWord first).
      	 html textInputWithCallback:
           [:w| (w = chosenWord second) ifTrue:
                [self increaseScore]]]]
      		




Alexandre Bergel                    17
Creating GUI (1/2)

     Displaying simple text:
 •
     html text: ‘My Text’
     Using different size:
 •
     html heading: aBlockOrText level: level
     html heading: aBlockOrString
     Link with action:
 •
     html anchorWithAction: aBlock text: aString
     TextField without any button:
 •
     html form: [... html textInputWithCallback: aBlock ...]




Alexandre Bergel                 18
Creating GUI (2/2)

     Using a form:
 •
     html form: [
       html textInputWithCallback: aBlock.
       ...
       html submitButtonWithAction: aBlock text: aString]
     Look at the class WAHtmlRenderer and
 •
     WAAbstractHtmlBuilder




Alexandre Bergel               19
CSS: to give a better look

     Use divNamed: aString with: aBlockOrObject
 •
     	html divNamed: 'title' with: [
     	 html text: 'Improve Language Skills'
     	].

     Or
 •
     	html divNamed: 'title' with: 'Improve Language Skills'




Alexandre Bergel                 20
CSS: defining the style

        Define a method named style on the seaside
    •
        component:
           WordLearningComponent>>style
            ^ ‘#title {
           	background-color: lightblue;
           	margin: 10px;
           	text-align: center;
           	color: blue;
           	font-size: 18pt;
           	margin-top: 400px}
           body {
           	background-image: url(quot;http://www.iam.unibe.ch/~bergel/
           catsEye_hst_full.jpgquot;);
           	background-repeat: no-repeat;
           	background-position: top center;
Alexandre Bergel
           
color: blue;}’
CSS: more info

     Supported by many web browsers
 •

     Where to get more information:
 •
     http://www.w3schools.com/css

     ZenGarden:
 •
     http://www.csszengarden.com/




Alexandre Bergel              22
call: / answer:

                       A>>m1
                        x := self call: B                      A
                        x printString


                       B>>m2                                   A
                                                               B
                         self answer: 69


                       A>>m1
                        x := self call: B
                                                               A
                        x printString
                         -> 69

                                                 components in browser
                       code

The framed B in the method m1 is a graphical object displayed as the window B
in the web browser. m2 is a method that is invoked in a callback i.e., when an
action on the component B is invoked such as a button pressed or a link clicked.
  Alexandre Bergel                          23
call: / answer:

      To transfer control to another component,
 •
     WAComponent provides the special method #call:.
     This method takes a component as a parameter, and
     will immediately begin that component's response
     loop, displaying it to the user.

     If a called component provides an argument to
 •
     #answer:, that argument will be returned from
     #call:. In other words, calling a component can yield
     a result.


Alexandre Bergel              24
Example: Sushi Shop Online



search component


                                  cart view component




 list component




                                   batch component




    Alexandre Bergel     25
Logical Flow

                                       Confirm
                                                              Shipping
                               buy                     yes
                   Fill cart          contents.
                                                              address
                                     Checkout?
                               no
                                                                ok

                                                             Use shipping
                                                  no
                                                              as billing
                                                              address?

                                           Billing             yes
                                          address

                                                               Payment
                                                  ok
                                                                infos

                                                                ok


                                                             Confirmation




Alexandre Bergel
                                                                            26
XHTML generation

     XHTML code is generated programmatically:
 •
     Store>>renderContentOn: html
     	html cssId: 'banner'.
     	html table: [
     		      html tableRowWith: [
     		      	        html divNamed: 'title' with: self title.
     		      	        html divNamed: 'subtitle' with: self subtitle.
     		      ]
     	].
     	html divNamed: 'body' with: task




Alexandre Bergel
                                                                       27
Control Flow

     WAStoreTask>>go
     	| shipping billing creditCard |
     	cart := WAStoreCart new.
     	self isolate:
     	 [[self fillCart. self confirmContentsOfCart] whileFalse].
     	self isolate:
     	 [shipping := self getShippingAddress.
     	 billing := (self useAsBillingAddress: shipping)
     		        	        	       	       ifFalse: [self getBillingAddress]
     		        	        	       	       ifTrue: [shipping].
     		        creditCard := self getPaymentInfo.
     		        self shipTo: shipping billTo: billing payWith:
     creditCard].
     	self displayConfirmation.
Alexandre Bergel
                                                                        28
Control Flow
     To fill in the cart:
 •
     WAStore>>fillCart
     	 self call: (WAStoreFillCart new cart: cart)
     To confirm contents of cart:
 •
     WAStoreTask>>confirmContentsOfCart
     	 ^ self call:
     		     ((WAStoreCartConfirmation new cart: cart)
     		     	       addMessage: 'Please verify your order:')
     Payment:
 •
     WAStore>>getPaymentInfo
     	^ self call:
     	 ((WAStorePaymentEditor new
     	    validateWith: [:p | p validate])
     	addMessage: 'Please enter your payment information:')

Alexandre Bergel
                                                               29
Control Flow

     answer returns the component itself
 •
     WAStoreFillCart>>checkout
      self answer




Alexandre Bergel
                                           30
Some Guidelines

     Tasks are used to embed the logical flow of an
 •
     application within the go method, whereas
     The rendering is in charge of components.
 •
     Hence, the entry point of an application should be a
 •
     task’s go method




Alexandre Bergel             31
Seaside

     Used in industries
 •
     More info on:
 •
     http://www.beta4.com/seaside2
     Seaside’s fathers: Avi Bryant and Julian Fitzell
 •
     Mailing list:
 •
     http://lists.squeakfoundation.org/listinfo/seaside




Alexandre Bergel               32
Part II:
Developing Web-based
    Applications
Outline

 1.   What is a Web-based Application?
 2.   Issues when Directly Dealing with HTML
 3.   Example: Sushi Shop Online
 4.   Seaside Approach
 5.   Manipulating Non-Linear Control Flow
 6.   Development Tools




Alexandre Bergel           34
What is a Web-based Application?

     A collection of functions that take HTTP
 •
     requests as input and produce HTTP responses
     as output.
     Logical part centralized
 •




Alexandre Bergel          35
Directly Manipulating HTML

     Stateless connection toward the server. State has to
 •
     be passed around for each connection.
     ASP, PHP
 •




Alexandre Bergel             36
What is a Web-based Application?



                                                     address.html
         flight.html


                      <a href=                                 <a href=                ...
                      ”address.html?cart=...”                  ”payment.html?
                                                               cart=...&address=...”
GET                                 GET
flight.html                          address.html?cart=...



                                   User: Web browser


   Alexandre Bergel                             37
Directly Manipulating HTML

     Applications are difficult to maintain:
 •
     – Adding, renaming, removing some state is difficult
     – Flow execution scattered in several files
     – Poor management of the bandwidth: state has to be
       passed for each action!




Alexandre Bergel               38
Common Issues with Classical Framework

     Applications are often tedious to use:
 •
     –   Do not use the back button!
     –   Do not duplicate the windows!
     –   “Press OK only once!!!”
     –   “Do you want to resend the form?”
     –   Cookies manipulations




Alexandre Bergel                39
Seaside Approach

     Each session has one unique ID kept over its life
 •
     time:
     – Users (web browsers windows) are distinguished
     Each action has one ID unique over the session:
 •
     – In the lifetime of a session, an action is unique (”press OK
       only once”)




Alexandre Bergel                 40
Non-Linear Control Flow

     The control flow of an application can always be
 •
     modified by the user when pressing the back button
     or by opening a new browser on the same url.




Alexandre Bergel            41
Backtracking State

     With seaside, an object can be backtracked using the
 •
     method:
     WASession>>registerObjectForBacktracking: anObject

     After each response sent to the client, Seaside
 •
     snapshots the registered objects by creating a copy
     and putting them into a cache.
     Pressing the back button on the browser restores
 •
     the state of the object which is in sync of the display.



Alexandre Bergel               42
Transaction

     In complex applications it is often the case that we
 •
     must ensure that the user is prevented from going
     back over a sequence of pages to make
     modifications.
     Controlling the control flow is implemented by the
 •
     method:
     Component>>isolate: aBlock

     It treats the control flow defined in the block as a
 •
     transaction. It makes sure that the user can move
     forward and backward within the transaction. Once
     completed, the user cannot go back anymore.
Alexandre Bergel              43
Debugging with Seaside

     When debugged, an application does not need to be
 •
     restarted or manually recompiled




Alexandre Bergel            44
Debugging
                               b
             a     1




                           2




                       3




Alexandre Bergel               c
             d
Toolbar

                                 (b) Halo




                     Component
                       Name
                                                        Library Browser
                                                    Inspector
                                                 System Browser




                   (a) Toolbar                                Source View
                                                            Rendered View



Alexandre Bergel                            46
Toolbar

     A toolbar is shown at the bottom of the web-
 •
     application during the development phase.
     It allows one to access some tools:
 •
     – New Session restart the application
     – Configure opens a dialog letting the user configure some
       settings
     – Toggle Halos shows or hides the halos (explained later)
     – Profile shows a detailed report on the computation time
       used to render the page
     – Memory Use display a detailed report on the memory
       consumption
     – XHTML start an external XML validator on this page

Alexandre Bergel                47
Halos

     When enabling the halos, every component gets
 •
     surronded by a thin grey line and a header giving the
     class name of the component and a set of buttons to
     run tools and to change the viewing mode.
     – System Browser opens an editor on the current
       component.
     – Inspector opens a view on the current component.
     – Library Browser opens an editor that lets a UI designer
       tweak the associated CSS-Stylesheets.
     – Source View provides a pretty-printed and syntax-
       highlighted XHTML view onto the source code .


Alexandre Bergel                 48
Benefits with Seaside

     With PHP: Control flow scattered into files
 •
     (flight.html, address.html, ...)
     With Seaside: Control flow = method calls
 •
     (getFlight, getAddress, ...)
     Bandwidth saved: session state is only stored on the
 •
     server side.
     It makes reuse easier!
 •




Alexandre Bergel             49

Mais conteúdo relacionado

Semelhante a 2006 Seaside

Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8
Frédéric Delorme
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Jesse Vincent
 
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdfAccount.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
anujmkt
 
Please distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfPlease distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdf
neerajsachdeva33
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 

Semelhante a 2006 Seaside (20)

TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8
 
GC in Smalltalk - Now What?
GC in Smalltalk - Now What?GC in Smalltalk - Now What?
GC in Smalltalk - Now What?
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
 
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdfAccount.h  Definition of Account class. #ifndef ACCOUNT_H #d.pdf
Account.h Definition of Account class. #ifndef ACCOUNT_H #d.pdf
 
AWS Summit DC 2021: Improve the developer experience with AWS CDK
AWS Summit DC 2021: Improve the developer experience with AWS CDKAWS Summit DC 2021: Improve the developer experience with AWS CDK
AWS Summit DC 2021: Improve the developer experience with AWS CDK
 
ruby on rails pitfalls
ruby on rails pitfallsruby on rails pitfalls
ruby on rails pitfalls
 
The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88
 
Please distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdfPlease distinguish between the .h and .cpp file, create a fully work.pdf
Please distinguish between the .h and .cpp file, create a fully work.pdf
 
TDD
TDDTDD
TDD
 
Emscripten - compile your C/C++ to JavaScript
Emscripten - compile your C/C++ to JavaScriptEmscripten - compile your C/C++ to JavaScript
Emscripten - compile your C/C++ to JavaScript
 
Testing Seaside Components
Testing Seaside ComponentsTesting Seaside Components
Testing Seaside Components
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-started
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-started
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Stories
 
T4
T4T4
T4
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 

Mais de bergel

Roassal presentation
Roassal presentationRoassal presentation
Roassal presentation
bergel
 

Mais de bergel (10)

Building Neural Network Through Neuroevolution
Building Neural Network Through NeuroevolutionBuilding Neural Network Through Neuroevolution
Building Neural Network Through Neuroevolution
 
Roassal presentation
Roassal presentationRoassal presentation
Roassal presentation
 
2011 famoosr
2011 famoosr2011 famoosr
2011 famoosr
 
2011 ecoop
2011 ecoop2011 ecoop
2011 ecoop
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
 
The Pharo Programming Language
The Pharo Programming LanguageThe Pharo Programming Language
The Pharo Programming Language
 
2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritance
 
Presentation of Traits
Presentation of TraitsPresentation of Traits
Presentation of Traits
 
2004 Esug Prototalk
2004 Esug Prototalk2004 Esug Prototalk
2004 Esug Prototalk
 
2005 Oopsla Classboxj
2005 Oopsla Classboxj2005 Oopsla Classboxj
2005 Oopsla Classboxj
 

Último

Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
dlhescort
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂EscortCall Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
dlhescort
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
daisycvs
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Sheetaleventcompany
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
daisycvs
 

Último (20)

Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceMalegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
 
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLWhitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂EscortCall Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
Call Girls In Nangloi Rly Metro ꧂…….95996 … 13876 Enjoy ꧂Escort
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 

2006 Seaside

  • 1. Programming with Seaside Alexandre Bergel Alexandre.Bergel@cs.tcd.ie LERO & DSG Trinity College Dublin, Ireland 1
  • 2. Part I: Seaside in a Nutshell
  • 3. Outline 1. What is Seaside? 2. Starting Seaside 3. Create new Seaside Component 4. Creating GUI 5. Using CSS 6. Interaction Between Components 3 Alexandre Bergel
  • 4. Introduction to Seaside Application server Framework • Useful for generating dynamic web pages • Web server application for Squeak (used in this • presentation) and VisualWorks. Works on the top of a webserver (Comanche, • Swazoo). Provides high-level API to handle navigation between • pages (links) and GUI. Alexandre Bergel 4
  • 5. Some of the Seaside Features Sessions as continuous piece of code • XHTML/CSS building • Callback based event-model • Composition and Reuse • Development tools • Interactive debugging • Multiple control flow • Alexandre Bergel 5
  • 6. Starting Seaside Start the server with: • WAKom startOn: 9090 Go to to access the counter component: • http://localhost:9090/seaside/counter Alexandre Bergel 6
  • 7. Component Responsibilities It is a subclass of WAComponent • It contains a State modeled as instance variables • The flow is defined by methods • Rendering (high-level API that generate XHTML) • Style (CSS) • Alexandre Bergel 7
  • 8. Counter Example WAComponent WACounter inherits from WAComponent. • WACounter count self session registerObjectForBacktracking: self. initialize count := 0 count := count + 1 increase count := count - 1 decrease html heading: count. renderContentOn: html html anchorWithAction: [self increase] text: '++'. html space. html anchorWithAction: [self decrease] text: '--'. WACounter class>>initialize self registerAsApplication: ‘counter’ Alexandre Bergel 8
  • 9. Creating new Component Designing a small application to memorize words in • a foreign language. Display a score to show the progress. • 2 ways of using: • – Adding a new word in the database – Entering a translation Alexandre Bergel 9
  • 11. Component Definition Definition of the main class: • WAComponent subclass: #Learner instanceVariableNames: 'words germanWord englishWord score' classVariableNames: '' poolDictionaries: '' category: 'WordLearning' Alexandre Bergel 11
  • 12. Variables Initialization List of entered words: • Learner>>words words ifNil: [words := OrderedCollection new]. ^ words Score (increased when an entered word is correct): • Learner>>score score ifNil: [score := 0]. ^ score Choose a word: • Learner>>chooseEntry ^ self words atRandom Alexandre Bergel 12
  • 13. Helper Methods Could we ask for a word? • Learner>>readyToGuessWord ^ self words notEmpty Increasing the score: • Learner>> increaseScore score := self score + 1 Alexandre Bergel 13
  • 14. Managing the Back Button Need to keep the history of the objects, in case of • pressing the back button on the web browser Learner>>initialize super initialize. self session registerObjectForBacktracking: self. A trace of the lifetime is kept. When the back button • is pressed, state previously recorded is restored. Alexandre Bergel 14
  • 15. Registration of the Application Application registration: • Learner class>>initialize self registerAsApplication: 'word' Alexandre Bergel 15
  • 16. Rendering (1/2) Learner>>renderContentOn: html • html heading: 'Improve your Language Skills'. html form: [ html text: 'English: '. html textInputWithCallback: [:w| englishWord := w]. html text: ' German: '. html textInputWithCallback: [:w| germanWord := w]. html submitButtonWithAction: [self words add: (Array with: englishWord with: germanWord)] text: 'Add Word'. ]. ... Alexandre Bergel
  • 17. Rendering (2/2) ... • html horizontalRule. self readyToChooseWord ifTrue: [ html heading: 'Your score is: ', self score asString. html form: [ |chosenWord| chosenWord := self chooseEntry. html text: (chosenWord first). html textInputWithCallback: [:w| (w = chosenWord second) ifTrue: [self increaseScore]]]] Alexandre Bergel 17
  • 18. Creating GUI (1/2) Displaying simple text: • html text: ‘My Text’ Using different size: • html heading: aBlockOrText level: level html heading: aBlockOrString Link with action: • html anchorWithAction: aBlock text: aString TextField without any button: • html form: [... html textInputWithCallback: aBlock ...] Alexandre Bergel 18
  • 19. Creating GUI (2/2) Using a form: • html form: [ html textInputWithCallback: aBlock. ... html submitButtonWithAction: aBlock text: aString] Look at the class WAHtmlRenderer and • WAAbstractHtmlBuilder Alexandre Bergel 19
  • 20. CSS: to give a better look Use divNamed: aString with: aBlockOrObject • html divNamed: 'title' with: [ html text: 'Improve Language Skills' ]. Or • html divNamed: 'title' with: 'Improve Language Skills' Alexandre Bergel 20
  • 21. CSS: defining the style Define a method named style on the seaside • component: WordLearningComponent>>style ^ ‘#title { background-color: lightblue; margin: 10px; text-align: center; color: blue; font-size: 18pt; margin-top: 400px} body { background-image: url(quot;http://www.iam.unibe.ch/~bergel/ catsEye_hst_full.jpgquot;); background-repeat: no-repeat; background-position: top center; Alexandre Bergel color: blue;}’
  • 22. CSS: more info Supported by many web browsers • Where to get more information: • http://www.w3schools.com/css ZenGarden: • http://www.csszengarden.com/ Alexandre Bergel 22
  • 23. call: / answer: A>>m1 x := self call: B A x printString B>>m2 A B self answer: 69 A>>m1 x := self call: B A x printString -> 69 components in browser code The framed B in the method m1 is a graphical object displayed as the window B in the web browser. m2 is a method that is invoked in a callback i.e., when an action on the component B is invoked such as a button pressed or a link clicked. Alexandre Bergel 23
  • 24. call: / answer: To transfer control to another component, • WAComponent provides the special method #call:. This method takes a component as a parameter, and will immediately begin that component's response loop, displaying it to the user. If a called component provides an argument to • #answer:, that argument will be returned from #call:. In other words, calling a component can yield a result. Alexandre Bergel 24
  • 25. Example: Sushi Shop Online search component cart view component list component batch component Alexandre Bergel 25
  • 26. Logical Flow Confirm Shipping buy yes Fill cart contents. address Checkout? no ok Use shipping no as billing address? Billing yes address Payment ok infos ok Confirmation Alexandre Bergel 26
  • 27. XHTML generation XHTML code is generated programmatically: • Store>>renderContentOn: html html cssId: 'banner'. html table: [ html tableRowWith: [ html divNamed: 'title' with: self title. html divNamed: 'subtitle' with: self subtitle. ] ]. html divNamed: 'body' with: task Alexandre Bergel 27
  • 28. Control Flow WAStoreTask>>go | shipping billing creditCard | cart := WAStoreCart new. self isolate: [[self fillCart. self confirmContentsOfCart] whileFalse]. self isolate: [shipping := self getShippingAddress. billing := (self useAsBillingAddress: shipping) ifFalse: [self getBillingAddress] ifTrue: [shipping]. creditCard := self getPaymentInfo. self shipTo: shipping billTo: billing payWith: creditCard]. self displayConfirmation. Alexandre Bergel 28
  • 29. Control Flow To fill in the cart: • WAStore>>fillCart self call: (WAStoreFillCart new cart: cart) To confirm contents of cart: • WAStoreTask>>confirmContentsOfCart ^ self call: ((WAStoreCartConfirmation new cart: cart) addMessage: 'Please verify your order:') Payment: • WAStore>>getPaymentInfo ^ self call: ((WAStorePaymentEditor new validateWith: [:p | p validate]) addMessage: 'Please enter your payment information:') Alexandre Bergel 29
  • 30. Control Flow answer returns the component itself • WAStoreFillCart>>checkout self answer Alexandre Bergel 30
  • 31. Some Guidelines Tasks are used to embed the logical flow of an • application within the go method, whereas The rendering is in charge of components. • Hence, the entry point of an application should be a • task’s go method Alexandre Bergel 31
  • 32. Seaside Used in industries • More info on: • http://www.beta4.com/seaside2 Seaside’s fathers: Avi Bryant and Julian Fitzell • Mailing list: • http://lists.squeakfoundation.org/listinfo/seaside Alexandre Bergel 32
  • 34. Outline 1. What is a Web-based Application? 2. Issues when Directly Dealing with HTML 3. Example: Sushi Shop Online 4. Seaside Approach 5. Manipulating Non-Linear Control Flow 6. Development Tools Alexandre Bergel 34
  • 35. What is a Web-based Application? A collection of functions that take HTTP • requests as input and produce HTTP responses as output. Logical part centralized • Alexandre Bergel 35
  • 36. Directly Manipulating HTML Stateless connection toward the server. State has to • be passed around for each connection. ASP, PHP • Alexandre Bergel 36
  • 37. What is a Web-based Application? address.html flight.html <a href= <a href= ... ”address.html?cart=...” ”payment.html? cart=...&address=...” GET GET flight.html address.html?cart=... User: Web browser Alexandre Bergel 37
  • 38. Directly Manipulating HTML Applications are difficult to maintain: • – Adding, renaming, removing some state is difficult – Flow execution scattered in several files – Poor management of the bandwidth: state has to be passed for each action! Alexandre Bergel 38
  • 39. Common Issues with Classical Framework Applications are often tedious to use: • – Do not use the back button! – Do not duplicate the windows! – “Press OK only once!!!” – “Do you want to resend the form?” – Cookies manipulations Alexandre Bergel 39
  • 40. Seaside Approach Each session has one unique ID kept over its life • time: – Users (web browsers windows) are distinguished Each action has one ID unique over the session: • – In the lifetime of a session, an action is unique (”press OK only once”) Alexandre Bergel 40
  • 41. Non-Linear Control Flow The control flow of an application can always be • modified by the user when pressing the back button or by opening a new browser on the same url. Alexandre Bergel 41
  • 42. Backtracking State With seaside, an object can be backtracked using the • method: WASession>>registerObjectForBacktracking: anObject After each response sent to the client, Seaside • snapshots the registered objects by creating a copy and putting them into a cache. Pressing the back button on the browser restores • the state of the object which is in sync of the display. Alexandre Bergel 42
  • 43. Transaction In complex applications it is often the case that we • must ensure that the user is prevented from going back over a sequence of pages to make modifications. Controlling the control flow is implemented by the • method: Component>>isolate: aBlock It treats the control flow defined in the block as a • transaction. It makes sure that the user can move forward and backward within the transaction. Once completed, the user cannot go back anymore. Alexandre Bergel 43
  • 44. Debugging with Seaside When debugged, an application does not need to be • restarted or manually recompiled Alexandre Bergel 44
  • 45. Debugging b a 1 2 3 Alexandre Bergel c d
  • 46. Toolbar (b) Halo Component Name Library Browser Inspector System Browser (a) Toolbar Source View Rendered View Alexandre Bergel 46
  • 47. Toolbar A toolbar is shown at the bottom of the web- • application during the development phase. It allows one to access some tools: • – New Session restart the application – Configure opens a dialog letting the user configure some settings – Toggle Halos shows or hides the halos (explained later) – Profile shows a detailed report on the computation time used to render the page – Memory Use display a detailed report on the memory consumption – XHTML start an external XML validator on this page Alexandre Bergel 47
  • 48. Halos When enabling the halos, every component gets • surronded by a thin grey line and a header giving the class name of the component and a set of buttons to run tools and to change the viewing mode. – System Browser opens an editor on the current component. – Inspector opens a view on the current component. – Library Browser opens an editor that lets a UI designer tweak the associated CSS-Stylesheets. – Source View provides a pretty-printed and syntax- highlighted XHTML view onto the source code . Alexandre Bergel 48
  • 49. Benefits with Seaside With PHP: Control flow scattered into files • (flight.html, address.html, ...) With Seaside: Control flow = method calls • (getFlight, getAddress, ...) Bandwidth saved: session state is only stored on the • server side. It makes reuse easier! • Alexandre Bergel 49