How to dinamically create URLs

From WebRatio WebML Wiki

Jump to: navigation, search


In WebRatio it's possible to create URLs dinamically using the Script Unit. In the script we create a URL to a particular action of the WebRatio application.

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 Unit "User confirmation" (with Custom URL Name = "registration"), then the Default Group of the user is changed in "registered user".

The Script Unit that creates the URL, contains the following script:

#input String userOID

import com.webratio.rtx.RTXConstants
import com.webratio.struts.WRGlobals;
import com.webratio.struts.HttpRequestHelper
import com.webratio.rtx.core.BeanHelper

/*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)

return confirmationURL


Related articles:
Category Difficulty Refers
Context Parameters Web Model Beginner Get Unit
Set Unit
Reset Unit
Create Unit Web Model Beginner Create Unit
Create a "Hello world" application Web Model Beginner Site View
WebML
WebRatio
Create a "Simple data centric" web application Web Model Beginner Site View
WebML
WebRatio
Custom Locations and Master pages Web Model Beginner Master Page
Custom Location
… further results












Did you find this article useful? Please rate it!

Rating: 0.0/5 (0 votes cast)

Personal tools