qexo-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qexo-general] Include, Http Post


From: Terje Pedersen
Subject: Re: [Qexo-general] Include, Http Post
Date: Sun, 20 Jul 2003 14:18:14 +0200
User-agent: KMail/1.5.1

> Terje Pedersen wrote:
> > I N C L U D E
> > Is it possible to compile an xql program and use functions from this
> > class just like you can do with java, scm classes? I have tested using
> > functions written in a custom scm class from xql which worked on the
> > command line but for some reason I didn't get i working with tomcat ie.
> > from a servlet.
>
> Note sure what you're asking here.  Yes, you can compile an xql program
> to a Java class, and yes you can call Java methods from XQuery.  The
> problem is these features aren't really integrated and consistent yet.
> This is a high priority issue.

Some kind of module support is needed soon so that I could split my xql code 
into several files.

> > H T T P  P O S T
> > But what I really would
> > like to have is a function returning the posted form data as xml so that
> > I can treat it just like an xml document with the possibilty to lets say
> > join it with some other xml data.

Since I posted this mail I have learned a lot about xquery and Qexo so I 
thought I should share some code generating xml from forms in Qexo itself (it 
doesn't support mulitple values from checkbox or select multiple yet) 

define function xml-request($names){
        document {
                element request {
                        for $n in $names
                        return element {$n} {request-parameter($n,())}
                }
        }
}

let $r := xml-request(("title","name","email","url","description"))/request
return
        <div>
        Name: {$r/name/text()}<br/>
        Email: {$r/email/text()}
        </div>

Sure the xml-request could also have one more parameter telling which root tag 
to generate.

If we now also had request-parameter-names returning a sequence of all names 
which were posted, you could write:

let $request := xml-request(request-parameter-names())

In HTTP.scm:
(define (request-parameter-names) :: <gnu.mapping.Values>
    (invoke-static <gnu.kawa.servlet.ServletCallContext> 'getParameterNames))

In ServletCallContext.java:

import java.util.Enumeration;

public static Values getParameterNames ()
{
        HttpServletRequest request = getRequest();
        Enumeration e = request.getParameterNames();
        Values vals = new Values();

        while(e.hasMoreElements()){
                vals.writeObject(e.nextElement());
        }
        return vals;
}

Example with a form:

let $names := request-parameter-names()
let $r := xml-request($names)/request
return
        <html>
                <head><title>Request test</title></head>
                <body>
                        Text: {$r/text/text()}<br/>
                        Radio: {$r/yesno/text()}<br/>
                        Checkbox: {$r/checkbox/text()}<br/>
                        Select: {$r/select/text()}<br/>
                        Select mulitple: {$r/selectmultiple/text()}<br/>
                        <form method="post" action="#">
                                <b>Text</b><br/>
                                <input name="text" type="text" size="30"/><br/>
                                <b>Radio</b><br/>
                                <input type="radio" name="yesno" 
value="yes"/>Yes<br/>
                                <input type="radio" name="yesno" 
value="no"/>No<br/><br/>
                                <b>Checkbox</b><br/>
                                <input type="checkbox" name="checkbox" 
value="Linux"/>Linux<br/>
                                <input type="checkbox" name="checkbox" 
value="Windows"/>Windows<br/>
                                <b>Select</b><br/>
                                <select name="select">
                                        <option key="A">A</option>
                                        <option key="B">B</option>
                                </select><br/>
                                <b>Multiple Select</b><br/>
                                <select name="selectmultiple[" multiple="true">
                                        <option key="House">House</option>
                                        <option key="Boat">Boat</option>
                                        <option key="Car">Car</option>
                                </select><br/>
                                <input name="submit" type="submit" value="Ok"/>
                        </form>
                </body>
        </html>

> That may be possible.  But I don't know if it's compatible with XForms,
> which we may want to work towards.

Yes I would really like to have XForms support in Qexo.

Terje Pedersen - address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]