Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to using URL parameters within the same session
#1
Hello,
right now we know how to handle URL parameters when starting a new session. What we do is call a StartupSession method like shown below


Code:
procedure TWebRegistrationServerController.IWServerControllerBaseNewSession(
 ASession: TIWApplication);
begin
 ASession.Data := TWebRegistrationSession.Create(nil, ASession);
 WebRegistrationSession.SetupSession;
end;



Then in the .StartupSession method we look at the parameters and do something like

Code:
WebRegistrationSession.StartupSession

aValue := WebApplication.Request.QueryFields.Values[aFieldName];
if aValue = option1 then
    FStartupForm:=Option1form.Create...
else if aValue = option 2
 FStartupForm:=Option2form.Create...

 
Then, in the ServerController I set the FStartupForm to the main form


Code:
procedure TWebRegistrationServerController.IWServerControllerBaseGetMainForm(
   var vMainForm: TIWBaseForm);
begin
 vMainForm := WebRegistrationSession.StartForm;
end;

In that way, the URL controls which form the session starts with.

But what if the session is runnig, and the user pastes a URL in the browser and I want to show a form within that session based on the URL?

For example, I am making a simple CMS system based on TinyMCE, as wrapped by the CGDevTools components. If I want the user to be able to link to pages within the CMS I need to have a link that refers to a custom page within the CMS in the same session. So the link will be something like www.whatever.com/$/customPage="my page name"

So I need to be able to detect those links within a current session and then update the page that is being viewed to the page in the parameters. How can I do that?
Reply
#2
(05-18-2018, 05:19 PM)davenovo Wrote: Hello,
right now we know how to handle URL parameters when starting a new session. What we do is call a StartupSession method like shown below


Code:
procedure TWebRegistrationServerController.IWServerControllerBaseNewSession(
 ASession: TIWApplication);
begin
 ASession.Data := TWebRegistrationSession.Create(nil, ASession);
 WebRegistrationSession.SetupSession;
end;



Then in the .StartupSession method we look at the parameters and do something like

Code:
WebRegistrationSession.StartupSession

aValue := WebApplication.Request.QueryFields.Values[aFieldName];
if aValue = option1 then
    FStartupForm:=Option1form.Create...
else if aValue = option 2
 FStartupForm:=Option2form.Create...

 
Then, in the ServerController I set the FStartupForm to the main form


Code:
procedure TWebRegistrationServerController.IWServerControllerBaseGetMainForm(
   var vMainForm: TIWBaseForm);
begin
 vMainForm := WebRegistrationSession.StartForm;
end;

In that way, the URL controls which form the session starts with.

But what if the session is runnig, and the user pastes a URL in the browser and I want to show a form within that session based on the URL?

For example, I am making a simple CMS system based on TinyMCE, as wrapped by the CGDevTools components. If I want the user to be able to link to pages within the CMS I need to have a link that refers to a custom page within the CMS in the same session. So the link will be something like www.whatever.com/$/customPage="my page name"

So I need to be able to detect those links within a current session and then update the page that is being viewed to the page in the parameters. How can I do that?

Take a look at the ContentHandlersDemo.  I think it does exactly what you are looking for.

Dan
Reply
#3
Hi Dan,

Aren't those for mapping a particular page to a static URL? i.e. you register a handler for a particular URL? In my case, I need to parse the parameter in order to determine the page in my application to show...
Reply
#4
(05-18-2018, 07:04 PM)davenovo Wrote: Hi Dan,

Aren't those for mapping a particular page to a static URL? i.e. you register a handler for a particular URL? In my case, I need to parse the parameter in order to determine the page in my application to show...

Those go from a page in your application to another page in your application, based on the URL it passes.  The URL syntax would be slightly different, but otherwise should do what you want.  That is, instead of passing a parameter you would pass the target as a page url.

I haven't tried it, but I think you could also branch a custom content handler based on ASession.RunParams.  Someone else may have input on that method if they've used it.

Dan
Reply
#5
Hi Dan,

Unless I am missing something you have to register the content handler with a fixed URL. At least in the example And there are a fixed number of content handlers registered. I am making a small CMS. The user can add pages, remove pages, rename pages at any time. Thus, it has to be dynamic somehow. I dont know in advance what pages are going to exist. To make it more complex, each user has their own private pages/public pages. So I cannot just register all the pages.
Reply
#6
(05-19-2018, 05:16 AM)davenovo Wrote: Hi Dan,

Unless I am missing something you have to register the content handler with a fixed URL. At least in the example And there are a fixed number of content handlers registered.  I am making a small CMS. The user can add pages, remove pages, rename pages at any time. Thus, it has to be dynamic somehow. I dont know in advance what pages are going to exist. To make it more complex, each user has their own private pages/public pages. So I cannot just register all the pages.

So if I understand, you are going to show static pages from your TForm pages but you want to retain the session.  You can go to static pages, but it effectively "leaves" the application.   Is that what you are trying to do?

If so, you can catch the parameter then use webapplication.TerminateAndRedirect(sTheURL), but that will terminate your session.  

If you do not wish to terminate your session then I'd suggest that you load another TForm based on the parameter.  That new TForm can be one you build on the fly (I do this a lot) or maybe one with a container that will hold your target static page.

There may be some tricks you can use to go to a static page, then return to your session (if you don't use multi-session), but I don't think it would be very reliable.  It's a lot better to have continuous IW session forms.

Sorry if I'm not understanding exactly what you are trying to do.

Dan
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)