Webclient Cookies

Forum to discuss the Web client version of Servoy.

Webclient Cookies

Postby joshuahysong » Mon Aug 08, 2011 10:51 pm

I have been banging my head against the wall trying to get the http plugin to work for one of our solutions.

I would like to be able to save text entered into a field as a cookie and then later, after closing and reopening the browser, be able to get that data from the cookie to have the field filled in already.

We need this to do a "remember me" checkbox on a login name field on our webclient solution.

Here is some test code I've been using.

runs on solution load to start the http client
Code: Select all
function onload () {
   plugins.http.createHttpClient('DexOnline')
}


onaction event for a button to create the cookie after text entered into test field
Code: Select all
function savecookie () {
   plugins.http.setHttpClientCookie( 'DexOnline',  'DexOnlineUID',  UID, 'ourwebsite.com', '/', 10000000, false)
}


onaction event for a button to put cookie data in the show variable.
Code: Select all
function testcookie () {
   var cookie = plugins.http.getHttpClientCookie( 'DexOnline', 'DexOnlineUID')
   show = cookie.getValue() + ' - ' + cookie.getComment() + ' - ' + cookie.getDomain() + ' - ' + cookie.getName() + ' - ' + cookie.getPath() + ' - ' + cookie.getSecure()
}


This all works great in a single session. Problem is that the cookie expires when the browser is closed. How can we make the cookie expire much later?

Thanks!
joshuahysong
 
Posts: 18
Joined: Thu Jul 21, 2011 7:04 pm

Re: Webclient Cookies

Postby jcompagner » Tue Aug 09, 2011 9:28 am

the http plugin is another browser by itself, so that is not the browser of the user.. You are creating another kind of browser on the server here (where the webclient code runs)

setting a cookie on the users browser is done by: application.setUserProperty("key","value");
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Webclient Cookies

Postby joshuahysong » Tue Aug 23, 2011 4:42 pm

I just ran a test using application.setuserproperty and it looks like that is going to work exactly as we'd like it to.

Thanks for the info! I never would have guess using that to set a browser cookie.
joshuahysong
 
Posts: 18
Joined: Thu Jul 21, 2011 7:04 pm

Re: Webclient Cookies

Postby pbakker » Mon Aug 29, 2011 5:06 pm

Keep in mind that the API in Servoy in client agnostic: a function to set a cookie wouldn't make a lot of sense if you'd be running a Smart Client, because it's a browser thing.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands


Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 6 guests