In WebRatio it's possible to create URLs dinamically using the Script Component. In the script we create a URL to a particular action of the WebRatio Application.
NOTE: The script code described in this article is valid up to WebRatio 6.x.
An URL is composed of the following parts:
- Url: the url where the application is deployed.
- Action: the particular action we want to activate with the url.
- Query string: all the parameters needed by the action in order to be executed.
- Crc: the crc code to protect the URL.
Suppose that we want to implement this user registration process:
- The user inserts his data, registrating in the application as an unconfirmed user.
- The application sends a confirmation mail to the user with a link.
- The user follows the link in the email and becomes a registered user.
In this example we need to send a mail containing a link to a particular action of the application. Refer to the following model:
Here the user data are inserted in the User table with the "unregistered user" Default Group and a mail is sent for the confirmation. The link contained in the mail activates the Selector Component "User confirmation" (with Custom URL Name = "registration"), then the Default Group of the user is changed in "registered user".
The Script Component that creates the URL, contains the following script:
#input String userOID
/*gets the request from the localContext*/
def request = localContext.get(RTXConstants.HTTP_SERVLET_REQUEST_KEY)
/*gets the session from the request*/
def session = request.getSession().getServletContext();
def requestHelper = (HttpRequestHelper) session.getAttribute(WRGlobals.HTTP_REQUEST_HELPER_KEY);
/*gets the URL of the application*/
def url = requestHelper.getAbsoluteURLContext(false, request)
/*defines the action to be activated*/
def action = "/registration.do"
/*defines the query string with all the parameters requested for the action execution*/
def queryString = "kcond1.userOID=" + userOID + "&rcond1.groupOID=1"
/*creates the URL for the confirmation, here the CRC is created by the requestHelper with the query string and the request as inputs*/
def confirmationURL = url + action + "?" + queryString + "&CRC=" + requestHelper.getCRC(queryString, request)