Seaside – how to change a page’s title

I know I’ve seen the answer to this before, but had a hard time tracking it down, so thought it worthwhile to post.

To change the web page’s HTML title (or any other head information) for a web component, create a method updateRoot: .  This method will be called when the component is rendered on the page – remember to always super the call too.

component>>updateRoot: anHtmlRoot
    super updateRoot: anHtmlRoot.
    anHtmlRoot title: 'fooTitle'.
    "do anything else you'd like to Root here too"

Updater examples with Scriptalicious & Seaside

The first of a series of coding vignettes in Seaside.

 Context: a web app with a form containing multiple input fields.  Instead of waiting to submit the form, I want the page to update another element every time an input is changed.  In this example, a total field.  Solution was used for a simple MoneyCounter application:

MoneyCounter>>renderContentOn: html html form id: 'f'; with: [

html table: [
    html tableRow:
     [html tableData: [html text: 'pennies'];
           tableData:
         [html textInput
           id: 'pennies';
 	   "on: #pennies of: self;"
           callback: [:value | self pennies: value];
 	   onChange: (html updater
                       id: 'total';
		       triggerFormElement: 'pennies';
 		       callback: [ :r  |  self renderTotalOn: r])
       ] ]

    etc.

    html tableRow:
      [html tableData: [html text: 'TOTAL'; space];
            tableData: [html span id: 'total' ; with: self total]]]]


MoneyCounter>>renderTotalOn: html

 html render: self total
MoneyCounter>>pennies: value
   pennies := value

MoneyCounter>>total
	^((pennies asInteger * 0.01) +  etc.   )

Continue reading Updater examples with Scriptalicious & Seaside