Example of using a cookie in a WAM

Date: 23 September 2011
Product/Release: LANSA for the Web (WAMs) V12 SP1
Abstract: A simple example to show how to store and retreive a cookie in a WAM
Submitted By: LANSA Technical Support
  1. Create a WAM with a webroutine in it and generate the XSL for the webroutine.
  2. Go to the design view -> XML
  3. Inside the <lxml:server-instructions> section, add the following cookie information
    <lxml:cookie name="TESTC">
    <lxml:value field-name="STD_NUM"/>
    <lxml:expires>Fri 30, Sep 2011 10:00:00 GMT</lxml:expires>
    <lxml:domain />
    <lxml:path />
    <lxml:secure />
  4. Some notes about the Cookie:
    The value of field STD_NUM will be read and stored in the cookie
    The cookie value will be placed in the field TESTC the next time the website is executed
    Expires could also be left blank. The cookie will then expire when the browser is closed.
  5. In the webroutine, create web_map (both) for TESTC and STD_NUM
    Define Field(#TESTC) Reffld(#STD_NUM) Desc('Cookie name')
    e.g Web_Map For(*both) Fields(#std_num (#TESTC *out))
  6. Switch to Design view -> Web Page.
  7. Drag and drop from the Webroutine Output tabs the two STD_NUM and TESTC fields onto the page.
  8. Drag and drop a push button from Weblet Template in the Favourites tab.
  9. Set the on_click_wrname for the push button to refer to itself (this property controls the name of the web routine to execute when the weblet is clicked)

The way this example works is that the value of std_num will be sent to the server each time the user clicks the button. This value will then be used by the server to generate a cookie to be stored in the client's machine. This cookie will be stored in the Temporary Internet Files directory. The next time the user loads the page, the website will load the value of the cookie onto the TESTC field and it will be shown on the page.