seaside tutorial. outline ● focus on components ● rendering basics ● rendering anchors with...

20
Seaside Tutorial

Upload: tracey-harris

Post on 18-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Seaside Tutorial

Page 2: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Outline

● Focus on components● Rendering basics● Rendering anchors with callbacks (next,

previous)● Call: of a built-in component (call the

STSDateSelectorDialog)

Page 3: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Component Rendering

● Seaside components:– Subclass WAComponent– Implement #renderContentOn:– Argument is “renderer” (WAHtmlRenderer

instance)

Page 4: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

ExamplerenderContentOn: html

html paragraph: 'This is a paragraph'.html unorderedList:

[html listItem: 'Item 1'.html listItem: 'Item 2'.html listItem: 'Item 3'].

Page 5: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Calendar

● Browse WAHtmlRenderer and especially superclass

● Complete STSCalendar● Demo

Page 6: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Anchors and callbacks

● Method #anchorWithAction:text: takes block and invokes it in response to following anchor

● Render loop (so far):– Handle callbacks– Render component

renderContentOn: htmlhtml

anchorWithAction: [self doSomething] text: 'Do something'

Page 7: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Anchors and callbacks

● Add “next” and “previous” buttons to calendar

Page 8: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Tasks and sequencing

● WAComponent>>#call:– Displays argument

● WAComponent>>#answer:– Returns from call:– Argument is return value of call:

Page 9: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Tasks

● Components whose primary responsibility are sequencing

● Subclass WATask and override #go● Complete ReservationTask:

– Create and call: a STSDateSelectorDialog– demo

Page 10: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Calendar should answer

● Modify STSCalendar so that it answers when user clicks date.

● Change ReservationTask so that it uses your calendar

Page 11: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Embedding components

● One component can nest other components:– Create child components in #initialize– Answer child components array in

#children– Send “html render: child” in

renderContentOn:

Page 12: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Catching answer

● In some cases parent component needs to “catch” answer of subcomponent.

● Use #onAnswer:

Page 13: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

initializesuper initialize.startDateSelector := STSCalendar new.endDateSelector := STSCalendar new.

startDateSelector onAnswer: [:v | self updateArrival: v].endDateSelector onAnswer: [:v | self updateDeparture: v].

Page 14: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

children^ Array with: startDateSelector with: endDateSelector

Page 15: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

renderContentOn: html“.... omitted code for form and button ....”html table:

[html tableHeadings: #('Arrival Date' 'Departure Date').html

tableRowWith: [html render: startDateSelector]with: [html render: endDateSelector]].

Page 16: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component
Page 17: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Task: Guessing game step 1

● Your image STSGuessingGame● Subclass WATask● Use #inform: and #request: to display

messages and get input● Demo

Page 18: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Task: Guessing game step 2

● Add counter for “number of tries”● Try both method-local variable and i-var● Compare behavior of above when using

“back” button

Page 19: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Task: Guessing game step 2

● Seaside's use of continuations captures values of method-local variables (back button “backs them up”) but not i-vars

● Add #initialize

initializesuper initialize.self session registerObjectForBacktracking: self.

Page 20: Seaside Tutorial. Outline ● Focus on components ● Rendering basics ● Rendering anchors with callbacks (next, previous) ● Call: of a built-in component

Snapshotting

● Objects registered for backtracking are sent #snapshot– Default impl is shallowCopy

● Restoring snapshot done with #restoreFromSnapshot: