Re: An example for PostableResource wanted

Mark I. Lubin writes:
 > 
 > By the way, back to the ReverseString.java, I see that you got the string
 > as 
 > String str = data.getValue("string");
 > Can you tell me, how can I get hold on more inputs form the Form ( in other
 > words , say I have more complex Form : a few string-inputs, text-field, 
 > radio-buttons). That can be used for real-life example, like this survey about
 > Jigsaw:
 > 
 > <STRONG>Please take a minute and complete the form about Jigsaw</STRONG>    
 > <FORM METHOD="POST" ACTION="....">                
 > Name: <INPUT NAME="name" SIZE=50><BR>
 > Email Address: <INPUT NAME="email" SIZE=50><BR>
 > <INPUT NAME="subject" TYPE="hidden" VALUE="COMMENTS"><P>
 > Type whatever you wish about Jigsaw:<P>             
 > <TEXTAREA NAME="content" ROWS=10 COLS=60></TEXTAREA> </P><P>
 > Do you like Jigsaw?<P>
 > <INPUT TYPE="radio" NAME="the type" VALUE="Yes">Yes<BR>
 > <INPUT TYPE="radio" NAME="the type" VALUE="No">No<BR>
 > <INPUT TYPE="submit" VALUE="send via email">  
 > <INPUT TYPE="reset"  VALUE="clear form and start over"> <BR>
 > </FORM>
 > 
 > Then server will collect the information and send copy to the user.

You can either:

a) Get each field value by its name attribute. So in the above
example, to get the value of the subject, you can say:
    String subject = data.getValue("subject");
   And get back the content of the subject field.

b) You can list all returned value (as is the case of the
PostableResource handle's method) by enumerating the keys from data,
and walking through them (see the code for
w3c.jigsaw.forms.PostableResource).

If there is something broken in this interface, it's time to raise
your voice...[I am not sure how case sensitivity is handled, and I am
not sure it matters].

In your case (the above example), you will probably want to use the
HtmlGenerator object, by doing somethiung like:

ppublic class JigsawSurvey extends PostableResource {

import w3c.jigsaw.html.*;

public Reply handle(Request request, URLDecoder data) {
    HtmlGenerator g = new HtmlGenerator("Jigsaw survey"); // set title
    g.append("<h1>The data you entered</h1>");
    g.append("<ul>");
    g.append("<li>your name: ", data.getValue("name"));
    g.append("<li>content: ", data.getValue("content"););
    g.append("<li>type: ", data.getValue("the type"));
    // Add as many append as you want
    g.append("</ul>");
    Reply reply = request.makeReply(HTTP.OK);
    reply.setStream(g);
    return reply;
}    
}

At this point, you probably want to read the api documentation at:
/User/api/w3c.jigsaw.html.HtmlGenerator.html
/User/api/w3c.jigsaw.forms.URLDecoder.html

Anselm.

Received on Sunday, 7 July 1996 21:37:07 UTC