[Seaside] Help understanding WATableReport

Dan Winkler heydan at post.harvard.edu
Tue Aug 24 16:01:36 CEST 2004


Thanks, Radoslav.  This example was quite helpful for me.

To help the other beginners, I'll spell out the steps I followed to see 
this working.  (And you can tell me if I have got any of this wrong.)

1.  Create a new subclass of WAComponent.  I called mine 
FactorialTableComponent and it looks like this:

WAComponent subclass: #FactorialTableComponent
	instanceVariableNames: 'report'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Dan'

It has one instance variable called 'report' which will be used to hold 
its subcomponent, a WATableReport.

2.  For convenience, give your FactorialTableComponent one class method 
called #initialize which registers it as an application with Seaside:

initialize
	self registerAsApplication: 'FactorialTable'

This will allow you to test your component by loading 
http://localhost:9090/seaside/FactorialTable into your web browser.

3.  Put Radoslav's example code under the instance side #initialize 
method of FactorialTableComponent:

initialize
	| rows columns |
	
	rows _ #(1 2 3 4 5 6).
	columns _ OrderedCollection new
  		add: (WAReportColumn selector: #yourself title: 'original'); 
		"selector gets perform:-ed on your data item"
  		add: (WAReportColumn selector: #factorial title: 'factorial');
		add: (WAReportColumn new  									"or if you want more control"
    			valueBlock: [:rowItem | rowItem even ifTrue: ['even'] ifFalse: 
['odd']];
    			clickBlock: [:rowItem | self inform: 'you clicked ', rowItem 
asString];
    			title: 'odd/even');
  		yourself.

	report _ WATableReport new rows: rows; columns: columns; rowPeriod: 1; 
yourself.

This creates the subcomponent and stores it in the 'report' instance 
variable.

4.  Create a #children method of FactorialTableComponent:

children
	^Array with: report.

This lets Seaside know what the subcomponents of 
FactorialTableComponent are, in this case just the one 
WATableComponent.  (I'm not sure why this is required by the Seaside 
framework -- it seems it would know when you call render: what your 
subcomponents are?)

5.  Create a #renderContentOn: method of FactorialTableComponent:

renderContentOn: html
   html render: report.

This says that the way you render your component is by rendering its 
subcomponent, the WATableReport stored in the instance variable 
'report'.

6.  Register your component by doing 'FactorialTableComponent 
initialize' in a workspace.


And that's it.  Now you can see your application in your web browser 
and click column headings to change the sort order.  (Note: I wish the 
framework would make each new sort also subsort by the previous sort so 
that for example if I have a table of dates and times I could sort 
first by time and then by date to get chronological order.  I can 
simulate most of this behavior by passing in sortblocks but it gets 
messy and doesn't really do what you want when columns are sorted in 
reverse order.)

-- Dan


On Aug 23, 2004, at 11:14 AM, radoslav hodnicak wrote:

> rows := #(1 2 3 4 5 6). "your data"
> columns :=
> OrderedCollection new
>  add: (WAReportColumn selector: #yourself title: 'original');
> "selector gets perform:-ed on your data item"
>  add: (WAReportColumn selector: #factorial title: 'factorial');
> "or if you want more control"
>  add: (WAReportColumn new
>    valueBlock: [:rowItem| rowItem even ifTrue: ['even'] ifFalse: 
> ['odd']];
>    clickBlock: [:rowItem| self inform: 'you clicked ', rowItem 
> asString];
>    title: 'odd/even');
>  yourself.
>
> ^WATableReport new rows: rows; columns: columns; yourself.
>
> produces table like
>
> original factorial odd/even
> 1        1         odd
> 2        2         even
> 3        6         odd
> 4        24        even
> 5        120       odd
> 6        720       even
>
> with the items in 3rd column clickable
>
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/listinfo/seaside




More information about the Seaside mailing list