send/formlet issue
svn: r13020
This commit is contained in:
parent
110098bc3b
commit
f5aa64f90b
|
@ -60,6 +60,8 @@
|
||||||
(build-path example-servlets "add-v2.ss"))
|
(build-path example-servlets "add-v2.ss"))
|
||||||
(test-add-two-numbers mkd "add-ssd.ss - send/suspend/dispatch"
|
(test-add-two-numbers mkd "add-ssd.ss - send/suspend/dispatch"
|
||||||
(build-path example-servlets "add-ssd.ss"))
|
(build-path example-servlets "add-ssd.ss"))
|
||||||
|
(test-add-two-numbers mkd "add-ssd.ss - send/formlet"
|
||||||
|
(build-path example-servlets "add-formlets.ss"))
|
||||||
(test-equal? "count.ss - state"
|
(test-equal? "count.ss - state"
|
||||||
(let* ([d (mkd (build-path example-servlets "count.ss"))]
|
(let* ([d (mkd (build-path example-servlets "count.ss"))]
|
||||||
[ext (lambda (c)
|
[ext (lambda (c)
|
||||||
|
|
|
@ -20,11 +20,16 @@
|
||||||
(test-equal?
|
(test-equal?
|
||||||
t
|
t
|
||||||
(let* ([d (mkd p)]
|
(let* ([d (mkd p)]
|
||||||
[k0 (first ((sxpath "//form/@action/text()") (call d url0 empty)))]
|
[r0 (call d url0 empty)]
|
||||||
[k1 (first ((sxpath "//form/@action/text()") (call d (format "~a?number=~a" k0 xs)
|
[k0 (first ((sxpath "//form/@action/text()") r0))]
|
||||||
(list (make-binding:form #"number" xs)))))]
|
[i0 (first ((sxpath "//form/input/@name/text()") r0))]
|
||||||
[n (first ((sxpath "//p/text()") (call d (format "~a?number=~a" k1 ys)
|
[r1 (call d (format "~a?~a=~a" k0 i0 xs)
|
||||||
(list (make-binding:form #"number" ys)))))])
|
(list (make-binding:form (string->bytes/utf-8 i0) xs)))]
|
||||||
|
[k1 (first ((sxpath "//form/@action/text()") r1))]
|
||||||
|
[i1 (first ((sxpath "//form/input/@name/text()") r1))]
|
||||||
|
[r2 (call d (format "~a?~a=~a" k1 i1 ys)
|
||||||
|
(list (make-binding:form (string->bytes/utf-8 i1) ys)))]
|
||||||
|
[n (first ((sxpath "//p/text()") r2))])
|
||||||
n)
|
n)
|
||||||
(format "The answer is ~a" (+ x y)))))
|
(format "The answer is ~a" (+ x y)))))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#lang scheme
|
||||||
|
(require web-server/servlet
|
||||||
|
web-server/formlets)
|
||||||
|
(provide (all-defined-out))
|
||||||
|
(define interface-version 'v1)
|
||||||
|
(define timeout +inf.0)
|
||||||
|
|
||||||
|
; request-number : str -> num
|
||||||
|
(define (request-number which-number)
|
||||||
|
(send/formlet
|
||||||
|
(formlet
|
||||||
|
(#%# "Enter the " ,which-number " number to add: "
|
||||||
|
,{input-int . => . the-number}
|
||||||
|
(input ([type "submit"] [name "enter"] [value "Enter"])))
|
||||||
|
the-number)
|
||||||
|
#:wrap
|
||||||
|
(lambda (f-expr)
|
||||||
|
`(html (head (title "Enter a Number to Add"))
|
||||||
|
(body ([bgcolor "white"])
|
||||||
|
,f-expr)))))
|
||||||
|
|
||||||
|
(define (start initial-request)
|
||||||
|
`(html (head (title "Sum"))
|
||||||
|
(body ([bgcolor "white"])
|
||||||
|
(p "The answer is "
|
||||||
|
,(number->string (+ (request-number "first") (request-number "second")))))))
|
|
@ -4,15 +4,23 @@
|
||||||
"lib.ss")
|
"lib.ss")
|
||||||
|
|
||||||
(provide/contract
|
(provide/contract
|
||||||
[send/formlet ((formlet/c any/c) . -> . any/c)])
|
[send/formlet (((formlet/c any/c))
|
||||||
|
(#:wrap (xexpr? . -> . response?))
|
||||||
|
. ->* . any/c)])
|
||||||
|
|
||||||
(define (send/formlet f)
|
(define (send/formlet f
|
||||||
|
#:wrap
|
||||||
|
[wrapper
|
||||||
|
(lambda (form-xexpr)
|
||||||
|
`(html (head (title "Form Entry"))
|
||||||
|
(body ,form-xexpr)))])
|
||||||
(formlet-process
|
(formlet-process
|
||||||
f
|
f
|
||||||
(send/suspend
|
(send/suspend
|
||||||
(lambda (k-url)
|
(lambda (k-url)
|
||||||
`(form ([action ,k-url])
|
(wrapper
|
||||||
,@(formlet-display f))))))
|
`(form ([action ,k-url])
|
||||||
|
,@(formlet-display f)))))))
|
||||||
|
|
||||||
(provide/contract
|
(provide/contract
|
||||||
[embed-formlet (embed/url/c (formlet/c any/c) . -> . xexpr?)])
|
[embed-formlet (embed/url/c (formlet/c any/c) . -> . xexpr?)])
|
||||||
|
|
|
@ -226,10 +226,16 @@ There are a few basic @tech{formlet}s provided by this library.
|
||||||
|
|
||||||
A few utilities are provided for using @tech{formlet}s in Web applications.
|
A few utilities are provided for using @tech{formlet}s in Web applications.
|
||||||
|
|
||||||
@defproc[(send/formlet [f (formlet/c any/c)])
|
@defproc[(send/formlet [f (formlet/c any/c)]
|
||||||
|
[#:wrap wrapper
|
||||||
|
(xexpr? . -> . response?)
|
||||||
|
(lambda (form-xexpr)
|
||||||
|
`(html (head (title "Form Entry"))
|
||||||
|
(body ,form-xexpr)))])
|
||||||
any/c]{
|
any/c]{
|
||||||
Uses @scheme[send/suspend] to send @scheme[f]'s rendering (wrapped in a FORM tag whose action is
|
Uses @scheme[send/suspend] to send @scheme[f]'s rendering (wrapped in a FORM tag whose action is
|
||||||
the continuation URL) to the client. When the form is submitted, the request is passed to the
|
the continuation URL (wrapped again by @scheme[wrapper])) to the client.
|
||||||
|
When the form is submitted, the request is passed to the
|
||||||
processing stage of @scheme[f].
|
processing stage of @scheme[f].
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user