[Bese-devel] UCW guidance

Asbjørn Bjørnstad asbjxrn at bjxrnstad.net
Tue Aug 30 16:28:03 UTC 2005


On 30 Aug 2005, at 11:35 PM, Marco Baringer wrote:

> Jan Rychter <jan at rychter.com> writes:

>> 4. I believe this question is similar to the one posted earlier by  
>> Tim
>>    Lavoie. I ended up writing the following piece of code:
>>
>> (defaction switch-to ((component main-menu) new-label)
>>   (setf (selected-item component) new-label)
>>   (switch-component (main.body (ucw::parent (ucw::parent  
>> component))) new-label))
>>
>> Needless to say, I find this to be rather ugly. There are two
>> ucw::parent calls because of the extra level of indirection that I  
>> had
>> to design in (see question 1), but even if it wasn't for that, I'd  
>> need
>> at least one ucw::parent call. There surely is a better way?
>>
>
> i'd do it like so:
>
> (defaction switch-to ((menu main-menu) new-label)
>   (setf (selected-item menu) new-label
>         (container.current-component-name (controlled-component  
> menu)) label))
>
> setting up the controlled-component slot should be done in the
> shared-initialize method of the component which contains the navbar
> (and presumably the 'content' component).
>
> if this seems like a good idea (at the very least better than the
> nothing we have now) i'll implement it in the example app.


The way I've done it is to have a slot "top-pane" in all components  
and work
my way down the tree. That way I can access different containers  
depending
on need. For example switching the content-pane becomes something like:

(defmacro bodyswitch-link (label component)
   `(<ucw:a :action (switch-component (content-pane (top-pane  
page)) ,component)
                     ,label))

(defmethod render-on ((res response) (page guest-navigation))
    (<:ul :id "contextnav"
       (<:li (bodyswitch-link "login" 'login))
       (<:li (bodyswitch-link "register" 'register-user)))

(Refactored from my real code, and not tested, but you get the Idea.)

I also switch menus and other components that are not in the body pane,
it becomes more tricky if the tree of components/containers becomes more
complex, but so far it's working.
-- 
   -asbjxrn




More information about the bese-devel mailing list