Le mercredi 30 mai 2007 à 09:35 +0200, Edi Weitz a écrit :
Hi,
sorry for the delay.
On Fri, 25 May 2007 06:47:57 -0700 (PDT), Timothy Schaeffer tschaef@sbcglobal.net wrote:
I propose that the types for easy-handlers be extensible by the users. I have pieces of markup which are used throughout our site which collect information from several fields into a class (in our case tied to a database with clsql). The names of the fields are related, but diffierent from the lists, arrays and hashes of the easy-handlers, Dates and addresses are two good examples, but there are others. I would like to be able to teach the easy handler to collect these for me and pass them as parameters. This cannot be done with functions as the :parameter-type because the functions passed as :parameter-type do not take the parameter name.
I don't really understand what you're trying to do that can't be done with REAL-NAME and a function designator for PARAMETER-TYPE. Maybe you can provide an example?
Voici a simple example of what I'm doing:
(defun form-date-input (&key name (label "Date") value (required nil)) .... (with-html-output-to-string (s nil :indent t) ... a bunch of input fields for getting a date in pieces, whose id attr is based on the name paramater... ))
;; A function to collect date pieces from fields in markup produced ;; by form-date-input. parm-name must be the same as given in the ;; name parameter in form-date-input. (defun date-parameter (parm-name) (flet ((parm (item) (non-negative-integer-parameter ; guess what this does :) (conc parm-name "-date-" (string-downcase (to-string item)))))) (let ((yyyy (parm 'year)) (mm (parm 'month)) (dd (parm 'day))) (ignore-errors (clsql-sys::parse-datestring (format nil "~4,'0D-~2,'0D-~2,'0D" yyyy mm dd))))))
The function passed as :parameter-type takes only the parameter value as a string (right?), so I cannot do this there; I'm really collecting several fields into one value.
I'd say that if it can't be done, then your task is probably too complicated for an "easy" handler, but maybe I'm missing something. The idea of DEFINE-EASY-HANDLER is that it is a convenience macro for 90% of the handlers one usually writes - the mundane ones. It was not intended as a general purpose tool for every conceivable Hunchentoot handler on Earth.
Understood. I may have had a bit too much coffee. And some part of me doesn't like seeing a hardcoded list of types. Ars longa.
Maybe I'll roll my own, define-hairy-wart-covered-handler maybe.
I still think letting :request-type be a custom getter is a good idea though; it is an easy change and be consistent with the way :parameter-type works.
Hunchentoot is a pleasure to work with!
That's good to know... :)
It's good to be true [-)
Tim S