[Seaside] WAComponent instances tree + proper page refreshing for user (back button) - confusion
petr.fischer at me.com
Wed Jan 10 09:44:17 UTC 2018
I'm slightly confused about - how to properly refresh instantiated WAComponent tree and when.
In the Seaside manual says (About Callbacks):
"Do not change state while rendering... Just produce output and define callbacks that do the fancy stuff you can’t do while rendering."
OK, then my small example:
1) Suppose I have a page - WAMyListPage (WAComponent sub class), which presents a list of items from DB table, easy.
2) When WAMyListPage is instantiated at the beginnig, it loads 10 rows from the DB, creates WAMyItem (WAComponent subclass) for every DB row and puts these WAMyItem instances to the WAMyListPage instance variable "items" (OrderedCollection)
3) WAMyListPage is rendered to the browser (render call on all WAMyItem "items" components)
4) User 1 clisks on the WAMyItem component from the rendered list (on the WAMyListPage) and goes into item detail page (detail page is not interesting here)
5) User 2 deletes 5 items/rows from the database (some way)
6) User 1 clicks browser back button and returns to the WAMyListPage, two cases can occur:
A) typically, the "list page" is cached in the browser and browser immediatelly renders the list page from the cache - with all 10 old items (no refresh, broken old view with some non existing items)
B) request from the browser to the Seaside app is made again (with old Seaside URL from browser history), then Seaside app just renders old state of WAMyListPage instance from the history and again - there is all 10 old WAMyItem items instantiated, so, broken again, old items in the view
My question - where can I do a proper refresh of WAMyListPage list items? (manual refresh button in the Seaside app is unacceptable)
Note: I can solve this by reloading WAMyListPage "items" instvar collection in every renderContentOn: (reload from DB, reload all WAMyItem instances) + instruct the browser to not cache any web page (in HTTP headers), so in point (6A) above, browser will ignore caching and make request to Seaside app again.
In this way, everything works, WAMyListPage is actual every time, but main Seaside rule "Do not change state while rendering" is violated (WAMyItems are reinstantiated in every renderContentOn:).
So, how do I face this? Thanks very much! pf
More information about the seaside