seaside: an innovative web application...

24
Seaside: An Innovative Web Application Framework Damien Cassou, Stéphane Ducasse and Luc Fabresse W4S08 http://www.pharo.org

Upload: others

Post on 20-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Seaside: An InnovativeWeb ApplicationFrameworkDamien Cassou, Stéphane Ducasse and Luc Fabresse

W4S08

http://www.pharo.org

Page 2: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Seaside A powerful, innovative and flexible framework Dedicated to build complex Web applications Live coding and debugging Support reusable Web components Secure by default Web 2.0 support (Ajax, Reef, ...) REST integration

W4S08 2 / 24

Page 3: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Books and Tutorials

Seaside http://www.seaside.st Seaside book http://book.seaside.st Seaside tutorialhttp://www.swa.hpi.uni-potsdam.de/seaside/

Seaside tutorialhttp://seaside.gemtalksystems.com/tutorial.html

TinyBlog tutorial Community: register to seaside mailing list and ask

questions

W4S08 3 / 24

Page 4: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Seaside Little History

Developed by A. Bryant and J. Fitzell Enhanced by L. Renggli and P. Marshall In production since 2002 Actively maintained by J. Brichau, S. Eggermont (web site

under full rewrite) Foundation of many Pharo success stories http://www.pharo.org/success

W4S08 4 / 24

Page 5: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Seaside in a Nutshell

Define reusable and stateful components Use a DSL for rendering components Compose components

◦ build coarser-grained components by encaspulation◦ schedule components with call: and answer: messages

A web application is just a root component Debug your application on the fly Use metadata to generate forms

W4S08 5 / 24

Page 6: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Seaside in Production Since 2002

W4S08 6 / 24

Page 7: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Cable eXpertise

W4S08 7 / 24

Page 8: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Quuve - debrispublishing.com

W4S08 8 / 24

Page 9: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Seaside Components

A component is:◦ an instance of a subclass of WAComponent◦ a reusable and stateful part of a Web page◦ rendered in HTML (<div>)

A Web application has a root component

WAAdmin register: WACounter asApplicationAt: 'counter'.

W4S08 9 / 24

Page 10: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

The Counter Web Application

W4S08 10 / 24

Page 11: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

WACounter

WAComponent subclass: #WACounterinstanceVariableNames: 'count'classVariableNames: ''package: 'Seaside−Examples−Misc'.

WACounter >> initializesuper initialize.count := 0

WACounter >> increasecount := count + 1

WACounter >> decreasecount := count− 1

W4S08 11 / 24

Page 12: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

From Components to Valid HTML

All components respond to renderContentOn: This method converts a component to valid HTML This message is automatically sent to components by

Seaside

W4S08 12 / 24

Page 13: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

HTML Rendering

renderContentOn: is dedicated to HTML generation parameter named html (WAHtmlCanvas) defines a DSL like

API to generate valid HTML

WACounter >> renderContentOn: htmlhtml heading: count.html anchorcallback: [ self increase ];with: '++'.html space.html anchorcallback: [ self decrease ];with: '−−'

W4S08 13 / 24

Page 14: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Live Debugging

WACounter>>decreaseself haltIf: (count−1 < 0).count := count− 1

W4S08 14 / 24

Page 15: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Walking the Application Stack

W4S08 15 / 24

Page 16: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Back Button

Pressing the back button of the browser desynchronizesserver and clientExample: Increment the counter 5 times (count = 5) Press the back button => the displayed value is 4 Increment the counter => the displayed value is 6

How to make it work properly?

W4S08 16 / 24

Page 17: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

A Counter Dealing with Back Button

Just declare the component state to be preserved

WACounter >> states^ Array with: self

W4S08 17 / 24

Page 18: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Plain Code in Callbacks

WACounter >> renderContentOn: htmlhtml heading: count.html anchorcallback: [count oddifTrue: [ self increase ]ifFalse: [self inform: 'Even number!'.count := count + 2]

];with: '++'.html space.html anchorcallback: [ self decrease ];with: '−−'

W4S08 18 / 24

Page 19: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Callback ExecutionPressing ++

shows

W4S08 19 / 24

Page 20: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

A Greeter Application

W4S08 20 / 24

Page 21: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Callbacks with the User Value

A Greeter component

Greeter >> renderContentOn: htmlhtml form: [html text: 'Username:'.html textInputcallback: [ :value | username := value ].html submitButtoncallback: [ self inform: 'Hi ', username ];text: 'Say Hello'. ].

W4S08 21 / 24

Page 22: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Did you see?!

No manual request parsing No XML configuration files No file/page

◦ don’t think in terms of pages◦ use components

No hardcoding of next page Live Debugging

◦ use the debugger to modify objects and proceed togenerate the HTML response

W4S08 22 / 24

Page 23: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

Conclusion

A Web application = a root component A component renders itself in HTML (renderContentOn:) An extensible DSL helps to easily generate HTML

W4S08 23 / 24

Page 24: Seaside: An Innovative Web Application Frameworkressources.unisciel.fr/pharo/Slides/Week4/C019-W4S08-Seaside.pdf · Seaside A powerful, innovative and flexible framework Dedicated

A course by

and

in collaboration with

Inria 2016

Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 Francehttps://creativecommons.org/licenses/by-nc-nd/3.0/fr/