|
Function Types |
|
|
At the beginning it can be confusing to decide which type of function we should use. There are three types of functions that can be used when developing applications. 1. Compile Time Functions: CScript Functions ( % Functions) They can be used in the properties of the elements used in the pages and they are called when the pages are being compiled. After the compilation is finished they do not exist anymore. If, for example, "Page Name: %vof(PAGE_NAME)" is the value of a text element, during the compilation this function will be replaced with the value it returns; e.g. "Page Name: Products". 2. Run Time Functions: MScript Functions ( @ Functions ) MScript Functions are executed by the MoreMotion AF during processing of a request at the server. The Java classes can call the MoreMotion AF's function resolver to execute the MScript functions embedded in the given strings. MoreMotion AF itself can resolve the MScript functions existing in the data source definitions to provide dynamic database queries. Where can we use MScript Functions?
If, for example, a RelDB Query contains MScript functions, they are resolved before the query is executed. SELECT * FROM customer WHERE ID = @vof(i:ID)
In this example, @vof(i:ID) is replaced with the value of the request parameter "ID" first and then the query is executed.
Resolving MScript functions using MoreMotion AF API If we are developing an ActionSerice, a DataService or a Process, we can resolve the MScript functions existing in strings as follows:
// For Services String myResolvedParameter = request.resolve(myParameter);
// For Processes String myResolvedParameter = resolve(myParameter);
3. Transformation Time Functions: XSL Functions XSL functions are executed at the XSL Transformation time. This is the last step of the request handling process .
MoreMotion Application Studio, provides the "$vof()" macro that helps to specify XSL functions in the element properties easily. This macro is expanded into the XSL functions during build. Examples:
The thing to keep in mind is whether it be the native XSL functions or be the XSL functions expanded from $vof() macros, are executed at the last step (4th step) of the steps given above; NOT before. Therefore the $vof() macro is used incorrectly in the following data base query and there will never be a result set that contains records. select * from customer where NAME = '$vof(NAME)' <-- WRONG USAGE!!!
In other words, we cannot use XSL functions where we are supposed to use MScript functions. Using a mixture of the functions It is possible to use different types of functions together. For example you should not be confused when you see such a definition: $vof(%vof(name))
%vof(name) is a CScript function and it will return the name of the current element. Assume that it is 'EMAIL'. After the %vof(name) is resolved what remains is $vof(EMAIL) which will be expanded to <xsl:value-of select="EMAIL"/>. Assume that you want to develop a database independent application and therefore you need to check the type of the database and execute a query according to this. You can accomplish using MScript functions that as follows
You can also do it as follows for a better performance:
After the compile-time functions executed, depending on the value of your build parameter s:dbtype, assume that it is 'mysql' the result will be:
See Build Parameters.
|