Maintaining State
Traditional web development passes state between pages as parameters in link URLs or hidden form fields. In Seaside, all the links are generated for you. How do you maintain state?
After an action callback finishes, the same component instance gets redisplayed. You can use its instance variables to store user interface state. These instance variables can be initialized in the component’s #initialize
method. For example, you could add a simple ’counter’ instance variable, and increase it every time the user clicks a certain link:
initialize
super initialize.
counter := 0.
renderContentOn: html
html heading: 'The counter is ', counter asString.
html anchor
callback: [ counter := counter + 1 ];
with: 'increase'.
Exploration
What happens when you use the browser back button with something like the simple counter described above? Compare that with the WACounter
example at /seaside/counter
. Is there a difference? Which behavior do you prefer? Which did you expect?