[Bese-devel] what don't i understand about select-field?
Ryan Davis
ryan at acceleration.net
Tue May 16 13:50:49 UTC 2006
I think the reason for the key-value and then index is so you can have
complicated structures as your option values seamlessly.
For instance, say you had a key of "Option 1", with a value being some
CLOS object. When rendering to the browser, you don't want to have:
<option value="#<FOO {C720971}>">Option 1</option>
So UCW makes an index variable to map between the option and your Lisp
value. This lets you think more in lisp and less in html.
Thanks,
Ryan Davis
Acceleration.net
Director of Programming Services
2831 NW 41st street, suite B
Gainesville, FL 32606
Office: 352-335-6500 x 124
Fax: 352-335-6506
Ties Stuij wrote:
> Greetings,
>
> I've been looking at the select classes in form.lisp and it seems to
> me there is a lot of double work going on while the benifit is not
> quite clear to me. Since you have your key-value pair ready already,
> why make an index also? Especially with entities like hash tables or
> alists which are supposed to have just one key to retrieve to begin
> with.
>
> Also i didn't really get the mapping-select abstraction, since it
> implements its only method, render-options, exactly the same as
> select-field, just with different names.
>
> Anyway as practice i made a select field which brings the amount of
> forms needed down from 12 to 4 (see below). It's the alist-select
> field from form.lisp except for that the value you're after is now
> already in client-value. On top of that i've built simpler select
> field, which in functionality is the same as a normal select-field.
> For the 'selected' attribute of options it compares the value, but
> that could easily be changed to key.
>
> As i said i made it for practice, but perhaps we could use these to
> replace the select fields of form.lisp? hash-table-select and
> plist-select are easily converted i think and the end result is faster
> and easier to read/use.
>
> But then again i probably missed the thing that's handy/good/practical
> about the current setup.
>
> ;; simple-select-field
>
> (defclass simple-select-field (generic-html-input)
> ((data-set :accessor data-set :initarg :data-set
> :documentation "An alist of values this select chooses
> from.")
> (test-fn :accessor test-fn :initarg :test-fn :initform #'string=
> :documentation "function to compare for :selected"))
> (:documentation "Form field used for selecting one value from a
> list of available options."))
>
> (defmethod render ((field simple-select-field))
> (<:select :name (make-new-callback
> (lambda (value)
> (setf (client-value field) value)))
> (render-options field)))
>
> (defgeneric render-options (select-field)
> (:documentation "Function used to render the list of options of
> a select field."))
>
> (defmethod render-options ((field simple-select-field))
> (dolist* ((key-string . value) (data-set field))
> (<:option :value value
> :selected (funcall (test-fn field) (client-value
> field) value)
> (<:ah key-string))))
>
> ;; simpler-select-field
>
> (defclass simpler-select-field (simple-select-field) ()
> (:documentation "needs just a list to render an option field, with
> the same
> value for the value as the name"))
>
> (defmethod render-options ((field simpler-select-field))
> (dolist* (value (data-set field))
> (<:option :value value
> :selected (funcall (test-fn field) (client-value
> field) value)
> (<:ah value))))
>
> greets,
> Ties
> _______________________________________________
> bese-devel mailing list
> bese-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/bese-devel
>
More information about the bese-devel
mailing list