[Bese-devel] Looking for a simple working example

Chris Dean ctdean at sokitomi.com
Sun May 21 01:31:20 UTC 2006


Rtveliashvili Denys <rtvd at mail.ru> writes:
> I recently downloaded and installed UnCommon Web. Everything works
> fine, but I have no luck in writing my own application based on UCW.

I'm a casual user of UCW, but the standalone code below works for me.
Maybe it will be a good starting point for you.

Hope it's useful!

Regards,
Chris Dean


(defparameter *sample-index*
  (make-instance 'cookie-session-application :url-prefix "/sample"
                  :dispatchers (list (regexp-dispatcher "^/?$"
                                       (call 'sample-home-page)))))

(defcomponent sample-home-page (simple-window-component) 
  ((value :accessor value-of :initarg :value :initform nil))
  (:default-initargs :title "Simple factorial"))

(defun factorial (n)
  (if (< n 2)
      1
      (* n (factorial (1- n)))))

(defmethod render ((sample sample-home-page))
  (<ucw:form :method "GET"
             :action (refresh-component sample)
             (<ucw:text :accessor (value-of sample))
             (<:submit :value "Calculate Factorial"))
  (when (value-of sample)
    (<:p (<:as-html (value-of sample))
         "! => "
         (<:as-html (factorial (parse-integer (value-of sample)))))))

(ucw:create-server :backend '(:httpd :port 8080)
                   :log-level (symbol-value '+debug+)
                   :start-p t)

(setf ucw:*inspect-components* t)

(register-application *default-server* *sample-index*)




More information about the bese-devel mailing list