[aida] Newbie question

Janko Mivšek janko.mivsek at eranova.si
Fri Oct 19 00:02:53 CEST 2007

nicolas petton wrote:
> Le jeudi 18 octobre 2007 à 17:09 +0200, Janko Mivšek a écrit :
>> Nicolas,
>> nicolas petton wrote:
>>> I'm working on a small blog engine, mostly to learn AIDA/Web.
>>> I've got a Blog, and some posts.
>>> In BlogApp>>viewMain, I want to display the posts :
>>> BlogApp>>vewMain
>>> 	|e|
>>> 	e := WebElement new.
>>> 	self observee posts do: [:each |
>>> 		e add: (PostApp new observee: each)].
>>> 	self pageFrameWith: e title: self observee title. 
>>> It does not work (return halt).
>>> What's wrong ?
>> e add: (PostApp new observee: each)
>> You don't need to make PostApp manually, it is automatically created 
>> when you access that domain object for a first time. What you need is to 
>> add a link to that domain object:
>> e addLinkTo: each text: eaxh title.
>> So, a whole viewMain would be:
>> BlogApp>>viewMain
>>   	|e|
>>   	e := WebElement new.
>>   	self observee posts do: [:each |
>>   		e addLinkTo: each text: each title.
>> 		e addBreak].
>>   	self pageFrameWith: e title: self observee title.
> Thank you Janko, but I want to display all posts, not links to them.
> In PostApp>>viewMain I have :
> viewMain
> 	|e|
> 	e := WebElement new.
> 	e addTextH1: self observee title.
> 	e addText: self observee contents.
> 	self pageFrameWith: e title: self observee title.
> A solution would be to rewrite this in BlogApp>>viewMain in a block, but
> I don't want to duplicate my code. That's why I wrote in
> BlogApp>>viewMain "e add: (PostApp new observee: each)".

Then try to put that e from PostApp>>viewMain in a separate method like 
#introElement and then in BlogApp simply call:

	e add: post webApp introElement.

But this is a bit hackish kind of reuse IMHO and I never do that way. If 
I really want to make a reusable part of web page, I make a special 
component (as subclass of WebElement) and reuse it elsewhere. But in 
your case it is just simpler to replicate that code in PostApp.

Best regards

Janko Mivšek
Smalltalk Web Application Server

More information about the Aida mailing list