[Bese-devel] forms (again)
Marco Baringer
mb at bese.it
Tue Nov 30 19:53:40 UTC 2004
i've been doing working on some very form intensive componets lately,
due to absurd (as far as i'm concerned) requests an the client's part
i can't just just out generate these so i find myself doing a lot of:
(defclass form ()
((form-slot :accessor form-slot)
(slot :accessor slot))
(:metaclass standard-component-class))
(defmethod (setf form-slot) (string (f form))
(setf (slot f) (parse-the-string string)))
(defmethod form-slot ((f form))
(convert-to-form-string (slot f)))
things get worse when you try to have a single slot in a
form-component which is draw with multiple input tags in the html
(example: dates which are handled by 3 select/option form
fields). this is getting unmanagebale. the issue is that we get text
from the user but we really want are lisp objects, i've got a couple
options which i've tried:
------------------------------
(defclass form ()
((slot :accessor slot :form-type float)
(other-slot :accessor slot :form-type date))
(:metaclass form-component-class))
the new :form-type slot option would specify:
1) how to transform the slot's value into a string suitable for
input's value attribute.
2) how to convert the string sent along the wire to a lisp object.
3) an as yet undecided form validation thingy.
4) a method on the generic accessor FORM-VALUE (which is what you'd
use in :accessor (yaclml) and ucw:accessor (tal) attributes.
------------------------------
the other option is to just write a macro (what i'm currently doing)
so you'd do something along these lines:
(defform form ()
(slot float))
it's basically the same thing, less typing and less control (and a lot
_more_ typing when you need that little bit of extra control (which
turns out to be way too often)).
i've a couple question which would love answers:
1) is the macro solution that much better than the metaclass solution
(the metaclass solution is more verbose but cleaner)?
2) is there some other route i'm missing?
------------------------------
this is the least-possible-change solution:
(defclass form ()
((slot :accessor slot :component input-text)
(other-slot :accessor slot :componet input-date)))
however this means you'll still need to write a good bit of munging
code when working with the slots' values. this also entails making
just about every form field be a component, which is a fair amount of
overhead for not much gain.
------------------------------
i keep coming back to this issue and nothing i come up with ever
satisfies me. suggestions? is there something i could steal from
CLIM's presentation types and input streams?
--
-Marco
Ring the bells that still can ring.
Forget your 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