I'm having problems understanding Swazoo. I saw a post earlier that
showed how to display 'Hello World' in the browser and I got that to work, but need something beyond that. I would like to display a page with a couple of input boxes and a submit button. I want to know how to receive the user input and be able to process it in Dolphin. Part of this is, I also need to know what special commands need to be added to the html page as well. Thanks! |
I think what you are looking for is to use a SwazooActivePageResource
and specify #uriPattern:filePath: (e.g. uriPattern: '/myapp' filePatch: 'c:\web\report.sap'. report.sap can look something like this: <html> <body> Hello Tim <ul> <? (1 to: 12) do: [:i | ?><li>Report <? ws nextPutAll: ('<P><P>' expandMacrosWith: i with: i). ?></li><? ]. ?> </ul> </body </html> So you can put normal html stuff in there (and code if you use the <? convention) - you can even use something like NVU to edit the file and design it wysiwyg. Having said all of this - I find that resource rather annoying and awkward to use. I have almost completed STemplate - which is a light wieght clone of the java Velocity or FreeMarker templating engines - I have a proper parser that fails fast and indicates where errors are. My templates look as follows: <html> <body> Hello Tim <ul> <#set x = 1 to: 12/> <#foreach y in x> <li> Report <a href='http://xxmagazine/${y!02u!}.htm'>Magazine ${y!02u!}</a></li> </#foreach> </ul> </body </html> If you want to "beta test" my work so far, I can send that on. My intention is that it will be an open source project. However the stuff already built into swazoo will certainly get you going. Tim |
In reply to this post by Michael Atkisson
Forgot to also mention - you can of course subclass Swazoo resource and
write to the response directly (see: GoodbyeCruelWorld - but use HttpResponse ok). I just find it gets a bit nasty doing this, and so you need to get an HtmlWriter goodie from someone or use file resources. Tim |
Thanks for your response. However I don't understand it.
|
Look at the class GoodByeCruelWorld - it has everything you need.
Specifically the method answerTo: aRequest | response | response := HTTPResponse notFound. response entity: '<html><head><title>Goodbye</title></head><body>I am not really here.</body></html>'. ^response In the above change the line HTTPResponse notFound. to HTTPResponse ok. In the entity String - put in any Html you need to build a form, if you don't know how to build forms, use a tool like NVU (or Dreamweaver or whatever) to build one, and then paste what it creates into that String. When you get that working, you can simplify it by having an object build that String (someone probably has a goody for you). If you are still stuck - I would suggest you read about Java Servlets (there's lots of good tutorials on those) - the same concepts apply and you can then use that to play with the code above. Tim |
I have created a web page
<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF"> <form method="post" action=""> <p> <input type="text" name="Name"> </p> <p> <input type="text" name="Address"> </p> <p> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html> I put it in a method named answerTo: When I call the the web page it works fine and displays what I expect. However I don't know how to access the values the users enters of the two input fields values in Dolphin, once I press the submit button. Thanks for your Help! |
Hi Michael,
Have a look at http://www.w3.org/TR/html401/interact/forms.html#h-17.13 for info on how the form data is submitted. If your form uses method="post", most of the server side of this is handled in HTTPPost. If you use method="get", it can be accessed via HTTPGet>>queryAt: Assuming you are using method="post" in your form, to access the data in your resource's #answerTo: method, you first need to check whether the request #isPost, and if so use HTTPPost>>postData* methods to access it. Do you have the "SZ Swazoo Authorization.pac" package? If so there is an example resource, AuthorizationResource, that checks whether a request is a GET or a POST and behaves differently for each. Hope this helps, Steve -- Steve Waring |
Thanks! I think I have a better idea of what to do.
|
Free forum by Nabble | Edit this page |