
Este hack mostra como usar #onAnswer. Para mais detalhes veja o link lá embaixo.
Criaremos 4 classe e seus métodos para obter imagens fáceis de seguir.
Crie a primeira classe com o código:
SeasideHack subclass: #OnAnswerHack
instanceVariableNames: ‘a’
classVariableNames: ”
poolDictionaries: ”
category: ‘Seaside-Hacks’
E os métodos:
initialize
super initialize.
a := A new
renderContentOn: html
html render: a
children
^ Array with: a
Crie a segunda classe com:
SeasideHack subclass: #A
instanceVariableNames: ”
classVariableNames: ”
poolDictionaries: ”
category: ‘Seaside-Hacks’
E os métodos:
renderContentOn: html
html div id: ‘letter-A’;
with: [html text: 'A'.
html
form: [html submitButton text: 'call B';
callback: [self call: B new]]]
style
^ ‘#letter-A {background-color: hotpink; width: 300px; height: 300px}’
Crie a terceira classe com:
SeasideHack subclass: #B
instanceVariableNames: ‘c’
classVariableNames: ”
poolDictionaries: ”
category: ‘Seaside-Hacks’
Com os métodos:
initialize
super initialize.
c := C new
renderContentOn: html
html div id: ‘letter-B’;
with: [html text: 'B'.
html render: c.
html
form: [html submitButton text: 'answer';
callback: [self answer]]]
style
^ ‘#letter-B {background-color: darkseagreen; width: 200px; height: 200px}’
children
^ Array with: c
E finalmente a quarta classe:
SeasideHack subclass: #C
instanceVariableNames: ”
classVariableNames: ”
poolDictionaries: ”
category: ‘Seaside-Hacks’
E os métodos:
renderContentOn: html
html div id: ‘letter-C’;
with: [html text: 'C'.
html
form: [html submitButton text: 'answer';
callback: [self answer]]]
style
^ ‘#letter-C {background-color: aquamarine; width: 100px; height: 100px}’
Para registrar a aplicação no Seaside execute:
OnAnswerHack registerAsApplication: ‘onanswerhack’
A execução da aplicação leva à aparição da seguinte figura:
Um clique no botão call B substitui o componente A pelo componente B e faz aparecer a figura:
O botão answer do componente B (botão de baixo) invoca self answer que retorna ao componente A, mas o botão answer no componente C, embedded em B, envia a mensagem self answer que não retorna para nenhum componente pois o componente C não foi invocado com self call:. No componente B a última linha do código abaixo (que você deve inserir agora) serve para interceptar o retorno e redirecioná-lo para o componente que invocou o componente B (o componente A):
initialize
super initialize.
c := C new.
c
onAnswer: [:dummy | self answer]
Fonte: Aprendendo a usar o método #onAnswer: em Seaside na prática: autenticação de usuários



0 respostas so far ↓
There are no comments yet...Kick things off by filling out the form below.
Deixe seu comentário