[Seaside] Help understanding WATableReport
C. David Shaffer
cdshaffer at acm.org
Wed Aug 25 17:41:22 CEST 2004
Dan and Radoslav,
Would you mind if I put your work together and put it on a web page? I
know that Avi has been collecting links to documents and this would be
one more to add to the list but I'd prefer, and I think others would as
well, a self-contained document rather than two or three e-mails to
follow. I'd list you two as authors of course. I don't do any fancy
formatting...see
http://www.cdshaffer.com/david/Seaside/TestingComponents/TestingComponents.html
or
http://www.cdshaffer.com/david/Seaside/Configurations/SeasideConfigurations.html
for examples. Once it's up there I'd undertake keeping it up to date
should there be future changes to Seaside which affect it.
David
Dan Winkler wrote:
> 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
>
>
>
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/listinfo/seaside
--
C. David Shaffer
http://www.cs.westminster.edu/~shaffer
http://www.shaffer-consulting.com
More information about the Seaside
mailing list