[Bese-devel] Re: accessing component via standard-application.

Marco Baringer mb at bese.it
Fri Jan 20 16:27:39 UTC 2006


Evrim ULU wrote:
> Marco Baringer wrote:
>> instances of standard-application represent an entire ucw application,
>>
>> with all the sessions and users it may have. there is no single
>> component tied to a standard-application. within a single
>> request/response loop there is a current "root" component which
>> represents the entire browser window as is available through
>> (context.window-component *context*)
> Hi Marco,
>
> So does this mean, there is no way to access components from
> outside the req/resp loop since context is not available?

yes.

> I've observed this also while trying to instantiate my widgets from
> repl. This behaviour is same with the java's app servers, i suppose. It
> makes testing very hard, is there a way to artificially produce a
> context, like in mock objects or cactus? Or Are there any better
> solutions? (i'm not happy with java's context-based solutions)

the problem is backtracking. whenever you create a component some of its
slot are setup for backtracking (the component specific slots,
calling-component and, afair, parent). if there's no context what should
we do with this? if you want a dummy context for testing maybe this will
help: (if you like this i'll include it in ucw proper (this is something
i have lying around and used to use from time to time))

(in-package :ucw)

(defclass dummy-request-context (standard-request-context)
  ())

(defclass dummy-request (httpd-request)
  ((query-path :initform "/DUMMY/index.ucw" :initarg :query-path)))

(defclass dummy-response (httpd-response)
  ()
  (:default-initargs :network-stream *trace-output*))

(defun make-dummy-context ()
  (let* ((dummy-app (or *default-application*
                        (make-instance 'standard-application
                                       :url-prefix "/DUMMY/")))
         (*context* (make-request-context dummy-app
                                          (make-instance 'dummy-request)
                                          (make-instance 'dummy-response)))
         (session (make-new-session dummy-app))
         (frame (make-new-frame session)))
    (setf (session.current-frame session) frame
          (context.session *context*) session)
    *context*))

(defcomponent dummy-root-component (window-component)
  ())

(defmethod render ((comp dummy-root-component))
  (<:as-html "DUMMY COMPONENT"))

(defmacro with-dummy-context ((&key (render t)
                                    (action t))
                              &body body)
  `(let* ((*context* (make-dummy-context))
          (self (make-instance 'dummy-root-component
                               :place (make-place
(context.window-component *context*)))))
     (setf (context.window-component *context*) self)
     (multiple-value-prog1
         ,(if action
              `(with-call/cc , at body)
              `(progn , at body))
       (when ,render
         (render (context.window-component *context*))
         (shutdown (context.response *context*))))))


you'd use it like so:

(with-dummy-context ()
  (call 'my-component))

which will 1) render my-component on *trace-output* so you can see the
html and 2) return the my-component instance so you can inspect it. NB:
this assumes *trace-output* is bivalent (can accept binary and characters)

hth.
-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen




More information about the bese-devel mailing list