mercoledì 1 agosto 2007

An HttpView2 Canvas sample

Here's a quick example on how to use the new Canvas system of HV2.

First of all, create an new TestView class as a subclass of HVTransientView:
HVTransientView subclass: #TestView
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Test'

Then, create a default method as follows:
| canvas |
canvas := self canvas.
canvas html:
[canvas head: [canvas title text: 'Test!'].
canvas body:
[canvas h1 text: 'A test of HV2''s new Canvas system'.
canvas p text: 'This is a simple test of the latest HV2 version']].
^ canvas

To start the engine, type the following on a Workspace then DoIt:
TestView startOn: 8080.

As soon as the HV2 engine has started, you can point your browser to http://localhost:8080/. Here's a screenshot of what you'll see:HV2's new canvas system.

You should also note that you can omit the ^ canvas expression in the default method. If you do so, HV2 will retrieve the response from the TestView instance itself.

Nessun commento: