Finally, the first(?) entry into a Webware Cookbook!
> -----Original Message-----
> From: webware-discuss-admin@...
> [mailto:webware-discuss-admin@... Behalf
> Of Albert
> Sent: Dienstag, 11. September 2001 10:46
> To: webware-discuss@...
> Subject: [Webware-discuss] "Forwarding" a page
> Sometimes, I'd like to "forward" a page to present the results
> of some processing. Usually, this new page does only show some
> message in the spirit of "Following data have been saved:
> One could write another page which contains just the necessary
> code, but I prefer not to clutter the directory with lots of
> servlets that have almost no functionality. Thus, I've written
> a method which allows to integrate the presentation of the
> results into the servlet.
> class MyPage (SidebarPage):
> # [...]
> def forwardPage(self, func):
> oldContent = self.writeContent
> self.writeContent = func
> self.writeContent = oldContent
> This method takes as argument the name of a method of MyPage
> (or a subclass of MyPage). self.writeContent is temporarily
> replaced with the new method "func". When self.writeBody() is
> called, it calls "func" instead of self.writeContent. After
> this, self.writeContent is replaced with the original method.
> You would use this method as follows:
> class SomePage (MyPage):
> def writeContent(self):
> """ this routine is called when SomePage is requested
> by the user"""
> self.write("<form>...</form>") # with a button that links
> #to self.processData()
> def processData(self):
> """ this is the routine which is called when the
> user presses the submit-button"""
> self.result = self.doSomeProcessing()
> def doSomeProcessing(self):
> """ proceess the form data. Usually, this method manipulates
> some attributes of ShowPage which can be used by
> e.g. lists of successful / unsuccessful manipulations"""
> return 1
> def showResult(self):
> """ this routine is called at the end of
> if self.result:
> self.write("The changes have been saved")
> self.write("Something has gone wrong")
> self.write('<a href="MainPage">Back to the main page</a>')
> This approach seems to work quite well. There is one caveat,
> though: self.forwardPage implicitly calls self.awake(). This
> might be a problem if you use self.awake() for the manipulation
> of the underlying model (e.g. add a row to a database table).
> What do you think about this construction?
> Albert Brandl
> Webware-discuss mailing list