[Lispweb] IMHO and defbindings.

mdanish@andrew.cmu.edu mdanish at andrew.cmu.edu
Wed Feb 20 16:23:30 CST 2002


On Wed, Aug 14, 2002 at 10:36:49AM -0400, Erik Enge wrote:
> Hi,
> 
> I'm new to this list, so if I'm barking up the wrong tree, just let me
> know and I'll move along quickly (and applogies for the interruption).
> 
> At the moment, I'm playing around with IMHO from OnShored.  I've got
> the basic webmethods, templates and applications up and running and
> talking with Apache.
> 
> Now, this is a piece of the code I have:
> 
> (defclass edit-issue (html-page)
>   ((issue
>    :reader issue
>    :initarg :issue)))

You should probably inherit from html-form instead.

> 
> (define-wm edit-issue ((caller t) (argument string))
>   (make-instance 'edit-issue
>                  :issue (get-issue (parse-integer argument))))

Change that to:

(define-wm process-edit-issue ((obj edit-issue))
  (with-element-values (description) obj
     (make-instance 'edit-issue
		    :issue description)))

html-form's look for a "process-<class name>" web-method.

not too sure what parse-integer would be used for? presumably you are
trying to get the value of the description box?

> 
> (defbindings edit-issue
>   ((description
>     :type text-area
>     :initargs (:cols 60 :rows 10 :value "text-area value"))
>    (submit-button
>     :type submit-button
>     :initargs (:value "Update"))))

I don't like defbindings that much myself; though craig says he uses it.
I have a feeling that my way of using IMHO is somewhat different than
craig and lyn, but whatever:

; without defbindings

(defmethod render-html ((obj edit-issue) stream)
  (html-stream stream
     (:table
       (:tr
	 (:td
	   (render-html (make-child self
				    'text-area
				    "description" ; unique name
				    :value (issue obj))
			stream)))
       (:tr
	 (:td
	   (render-html (make-child self
				    'submit-button
				    "submit-button"
				    :value "Update")
			stream))))))

Note that the table was added by me, as I am presuming you are using
templates and a similar structure within them.

It's a bit more verbose but I've created various macros to help shorten
it quite a bit.  Things such as RENDER-TEXT-AREA and RENDER-SUBMIT-BUTTON
for example.

I also use a macro called ENSURE-CHILD which acts like MAKE-CHILD
except that it checks to see if a child by that internal-name already
exists, and returns that instead.  It plays a little with the MOP to
change the slot-values of the child if you supply initargs.

Basically the effect of it is to preserve the hierarchy of html-elements
so that data can persist in-place in the objects.  I believe that others
use a global hash-table to store session-persistant data.

In the applications I've written, though, I've not had any memory problems
however, and they are used by 30+ people per day I'm pretty sure.

I should probably release my macros with a small write-up too. IMHO sure 
could use more docs anyway =)

> 
> What I would like to do here, to start with anyway, is to swap the
> "text-area value" for the value that's in the 'issue' instance's
> description slot.  I've tried:
> 
>     :initargs (:cols 60 :rows 10 :value (description issue)))
> 
> but that doesn't help (neither does the fact that I'm pretty new to
> Common Lisp).

You should have a good understanding of CLOS before you tackle this;
though admittedly I learned a good deal of CLOS while learning this.

You will realize that there are two main hierarchies: the class-hierarchy
starting with html-element, and the hierarchy that is an HTML document.
Knowing how method-combination and dispatch works will clue you into
the order in which the various methods are called to create the HTML
document, and understanding multiple-inheritance will help you piece
together new classes.

> 
> Later, I would like to know how I can specify:
> 
>    http://localhost/imho/app/some-method?id=1&name=2
> 
> and bind them to variables like "argument" (above) is.

(define-wm some-method ((obj t) args)
  ...)

Note that last time I checked, IMHO can only accept one argument.
What I've done in the past is something like somemethod?ARG1,ARG2.

> 
> Oh, and could someone explain to me what gets bound to the "caller" in
> edit-issue?

When process-edit-issue is called, it is supplied with the object of
type edit-issue that is the parent of the submit-button object which
was pressed.  Basically the object of the form =)

> 
> If it helps, I'm running CMUCL and the Debian package of IMHO for
> Debian 3.0.

Same here.

> 
> Any help and pointers would be greatly appreciated.  Thanks!
> 
> Erik.

Hope I understood the question correctly.

-- 
; Matthew Danish <mdanish at andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."



More information about the lispweb mailing list