3 mechanisms to reuse components:
call:
/ answer:
mechanism3 mechanisms to reuse components:
call:
/ answer:
mechanism
WACounter
WATwitterCounter
WAMultiCounter
WAExampleComponent subclass: #WAMultiCounter
instanceVariableNames: 'counters'
classVariableNames: ''
package: 'Seaside-Examples-Misc'.
WAMultiCounter >> initialize
super initialize.
counters := (1 to: 5) collect: [ :each | WACounter new ].
WAMultiCounter >> children
^ counters
WAMultiCounter >> renderContentOn: html
counters do: [ :each | html render: each ]
A composite:
counters
)render:
to subcomponents in its renderContentOn:
methodchildren
to return the collection of its subcomponents WAExampleComponent subclass: #MyApp
instanceVariableNames: 'children'
classVariableNames: ''
package: 'Seaside-Examples-Misc'.
MyApp >> initialize
super initialize.
children := { Greeter new.
WATwitterCounter new. WACounter new }.
MyApp >> children
^ children
MyApp >> renderContentOn: html
children do: [ :each | html render: each ]
separatedBy: [ html line ]
MyApp >> initialize
"..."
selectedChild := children first
MyApp >> renderContentOn: html
self renderMenuOn: html.
html render: selectedChild
MyApp >> renderMenuOn: html
html unorderedList: [
self children doWithIndex: [ :child :i |
html listItem: [
html anchor
class: 'selected' if: child = currentComponnent ;
callback: [ selectedChild := self children at: i ];
with: child className
] ] ]
3 mechanisms to reuse components:
call:
/ answer:
mechanism
WATwitterCounter >> renderContentOn: html
"..."
html tbsButton beDefault;
callback: [ self setCountToUserValue ]; with: 'Set Value'
"..."
WATwitterCounter >> setCountToUserValue
| webDialog newCounterValueByUser |
webDialog := WAInputDialog new
addMessage: 'Enter a new value for the counter:';
default: '0';
label: 'Ok';
yourself.
newCounterValueByUser := self call: webDialog.
count := newCounterValueByUser asNumber
WAInputDialog
answer:
a resultWAInputDialog >> renderContentOn: html
html form
defaultAction: [ self answer: value ];
with: [
html div: [
html textInput on: #value of: self.
html space.
html submitButton
callback: [ self answer: value ];
text: self label ] ]
3 mechanisms to reuse components:
call:
/ answer:
mechanismTasks are simple components:
renderContentOn:
)call:
/answer:
behind the sceneWATask subclass: #Adder
instanceVariableNames: ''
classVariableNames: ''
package: 'SeaExample'
Adder >> go
| value1 value2 |
value1 := self request: 'first number'.
value2 := self request: 'second number'.
self inform: value1 asNumber + value2 asNumber
WAAdmin register: self asApplicationAt: 'Adder'.
request:
uses call:
/ answer:
on a WAInputDialog
WAComponent >> request: aRequestString label: aLabelString default: aDefaultString onAnswer: aBlock
"Display an input dialog with the question aRequestString, the button label aLabelString and the default string aDefaultString. Passes the answer into aBlock."
self
call: (WAInputDialog new
addMessage: aRequestString;
default: aDefaultString;
label: aLabelString;
yourself)
onAnswer: aBlock
inform:
uses call:
/ answer:
on a WAFormDialog
WAComponent >> inform: aString onAnswer: aBlock
"Display a dialog with aString to the user until he clicks the ok button. Continue by evaluating aBlock."
self
call: (WAFormDialog new
addMessage: aString;
yourself)
onAnswer: aBlock
Seaside provides:
call:
/ answer:
/