Official Content

The way to work with external files, directories, web sessions, cookies,  mail sessions, etc., is through variables of special Data Types.

By defining a variable of the WebSession data type, you can create a session on the Web Server to maintain global variables. By defining a variable of the Directory Data Type, you can create, move or delete a directory from your file system. By defining a variable of the XMLReader Data Type, you can read an XML file. And so it goes on.

How can you achieve this? Through Properties and Methods related to these Data Types (each one will have a set of particular properties and methods, according to the subject it represents).

Example

Consider a site where the user must authenticate through a username and a password that are previously recorded in the database (a WebUser table exists to that end). We want to recover the user in every page visited, showing his or her name, and, for example, only their preferences.  Because of that, a websession variable is needed to get the user in every page. Suppose that a 'Home' web panel is created for login purposes, with the input variables &User and &Password put on the form (to get those values from the user). We will define a webSession variable (&session) on the 'Home'  web panel to set the user's name, that later could be get from every other page visited.

Therefore, in the event associated to the login (for example: Enter) we can do the following:

For each
    Where WebUserName = &User
    Where WebUserPsw = &Password
          &Session.Set(“Name”, WebUserName)
          Call (HWelcome)
    When none
          ... //Not valid user
Endfor

See how the &Session variable let's you define a "Name" global variable on the Server, and set it with the WebUserName -through the Set method of the variable.

Then, in the Start event of any other object, we can get that value for the user, through the Get method:

&UserName = &Session.Get( "Name" )

 As you can see, we have created a variable of the WebSession extended data type and handle it through methods. This is just a particular case of the more general one: all extended data types have the same behavior.







Subcribe to this category's changes
Sub CategoriesAdd a new subcategory in this category
PagesAdd a new page in this category
Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant