PDA

View Full Version : trying to get POST to work


javadog
08-13-2003, 12:00 PM
Hi,

I'm trying to test the ability to send parameters, but I can't seem to get the POST to work, I have no problem with GET.

I stole the method example from the docs, and copied the "hello.jsp" in the examples directory to my-apps where I'm running this LZX:


<canvas debug="true">

<dataset name="dsSendData" autorequest="false" src="hello.jsp" type="http"/>

<class name="postview" extends="view" visible="true" x="20" height="120">
<method name="sendData" args="action">
var d=canvas.datasets.dsSendData;
var p=new LzParam();
p.addValue( "action", action, true);
p.addValue( "firstName", "Bob", true);
p.addValue( "lastName", "Jones", true);
p.addValue( "phone", "415-255-2392", true);
p.addValue( "email", "bob@jones.com", true);
d.setQueryString( p );
d.doRequest();
</method>
</class>

<simplelayout axis="y"/>

<view>
<simplelayout axis="y"/>
<postview name="newPOST">
<button width="80" x="200" y="10">Send params
<method event="onclick">
parent.sendData("insert");
</method>
</button>
</postview>
</view>

</canvas>


I don't see any access of the hello.jsp file when I press the "Send params" button. Am I missing something fundamental here?

Thanks,

j-dog

antun
08-13-2003, 12:23 PM
You'd call the setQueryType() method:

http://www.laszlosystems.com/developers/learn/documentation/lzxref/httpdatasource.php#meth-setQueryType

Something like:


d.setQueryType('POST')


The LPS will POST to your back-end (since I gather that's what your JSP is expecting), but it will be a GET request between the client and the LPS. See here for more on that:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=316&highlight=POST

-Antun

javadog
08-13-2003, 01:04 PM
Hi Antun,

Still no luck. Is there any way to add more debug info to see what's happening with the doRequest?

Here's my log output:

13 Aug 2003 13:55:17 (127.0.0.1 42) INFO servlets.LZServlet - Request for C:\lps-v1\jakarta-tomcat-4.1.12\webapps\lps-v1\my-apps\simplepost.lzx
13 Aug 2003 13:55:17 (127.0.0.1 42) INFO response.Response - GET request from: 127.0.0.1
13 Aug 2003 13:55:17 (127.0.0.1 42) INFO compiler.Compiler - compiling C:\lps-v1\jakarta-tomcat-4.1.12\webapps\lps-v1\my-apps\simplepost.lzx...
13 Aug 2003 13:55:18 (127.0.0.1 42) INFO compiler.Compiler - done
13 Aug 2003 13:55:18 (127.0.0.1 42) INFO response.ResponseCompile - Responding with HTML wrapper for C:\lps-v1\jakarta-tomcat-4.1.12\webapps\lps-v1\my-apps\simplepost.lzx
13 Aug 2003 13:55:18 (127.0.0.1 43) INFO servlets.LZServlet - Request for C:\lps-v1\jakarta-tomcat-4.1.12\webapps\lps-v1\my-apps\simplepost.lzx
13 Aug 2003 13:55:18 (127.0.0.1 43) INFO response.Response - GET request from: 127.0.0.1
13 Aug 2003 13:55:18 (127.0.0.1 43) INFO response.ResponseSWF - Requesting object for C:\lps-v1\jakarta-tomcat-4.1.12\webapps\lps-v1\my-apps\simplepost.lzx
13 Aug 2003 13:55:18 (127.0.0.1 43) INFO response.ResponseSWF - Sending SWF, 125785 bytes

j-dog

antun
08-13-2003, 01:23 PM
I use the Proxomitron for debugging - it's an absolute lifesaver:

http://www.proxomitron.info/

It acts like a proxy, which means you point your browser at it. Always have it set on Bypass when working with Laszlo (in fact, just set it to default to Bypass mode permanently, because you get strange behaviour with caching). On a Windows machine you'll probably need to reboot in order to have the new browser settings take effect.

Basically open Proxomitron's log window, and that should show you if the requests are leaving the browser.

-Antun

javadog
08-13-2003, 01:47 PM
Hi Antun,

Do you have a working example of an application I can try on laszlosystems.com that uses a doRequest() with a setQueryString(params)?

Thanks,

j-dog

antun
08-13-2003, 02:06 PM
Sure - the Weather app:

http://www.laszlosystems.com/lps-v1/viewer/viewer.jsp?file=/sample-apps/weather/weather.lzx

-Antun

javadog
08-14-2003, 10:18 AM
It turns out that the LzParam doesn't work as documented in the method found on the LzParam reference page (http://www.laszlosystems.com/developers/learn/documentation/lzxref/lzparam.php).

I changed the method from:

<method name="sendData" args="action">
var d=canvas.datasets.dsSendData;
var p=new LzParam();
p.addValue( "action", action, true);
p.addValue( "firstName", "Bob", true);
p.addValue( "lastName", "Jones", true);
p.addValue( "phone", "415-255-2392", true);
p.addValue( "email", "bob@jones.com", true);
d.setQueryString( p );
d.doRequest();
</method>

to:

<method name="sendData" args="action">
var d=canvas.datasets.dsSendData;
d.setQueryString({action: action,
firstName: "Bob",
lastName: "Jones",
phone: "415-255-2392",
email: "bob@jones.com"});
d.doRequest();
</method>

and now it works.

In debugging this, I tried using the following statement after the setQueryString() call, but it did not return the query string:

Debug.write("Query string: " + d.getQueryString());


j-dog

antun
08-14-2003, 11:08 AM
Hey j-dog

Oops! There has been a bug filed on this issue. The problem happens when you pass an LzParam instance into a setQueryString() method - after that all doRequest() calls are ignored.

My apologies for not picking up on this sooner.

The getQueryString() seems great for debugging - I might use it as a tip 'o the week.

-Antun

javadog
08-14-2003, 12:19 PM
Hi Antun,

I imagine the same bug prevents the getQueryString() method from working?

I hope you will also file two bugs against the documentation, one for the aforementioned LzParam reference page, and the other for the code example found here in the "Data-driven Apps" example:

http://www.laszlosystems.com/developers/learn/documentation/tutorials/data_app_8.php

Hopefully that will prevent others from running into the problem, and make your job easier.

j-dog

antun
08-14-2003, 02:55 PM
Hey j-dog

Yep, I have filed those bugs:

#1945 - the tutorial
#1946 - the LzParam

The bug numbers won't mean much to you, but at least you know that they're logged. They won't make it into the forthcoming release, but they will make it into the one after that.

-Antun