ExperShop - DynHtmlHome Contents Please email any bug reports, comments or suggestions to ExperLog's Online Support OverviewDynHtml is a technology dedicated to include database and other dynamic content in HTML pages.DynHtml pages are expanded on-the-fly by ExperSHOP, and database query results are included in the HTML text (as well as other possible dynamic information, such as HTTP parameters for example). DynHtml templates are ascii files that mix HTML with specific DynHtml tags: they are expanded at run time, to display dynamic information.
How to write a DynHtml templateHere's an example of DynHtml template:
<html><body> <b>Customer List</b><p> $DefineSql GetCustomers SELECT FirstName, LastName FROM Customer $IfPresent AgeMin $AppendSql GetCustomers WHERE Age>AgeMin $Endif $ExecSql GetCustomers $IfNoResult GetCustomers There's no Customer. $Else $LoopOnResults GetCustomers cust Customer Name: $cust:FirstName$, $cust:LastName$<br> $EndLoop $EndIf </body></html> The values
of FirstName and LastName returned in the query results will appear in
the browser in place of $cust:FirstName$ and $cust:LastName$; Customer List Customer
Name: Paul, Smith Note the "$IfPresent... $Endif" statement: if the DynHtml template is invoked with an HTTP parameter named "AgeMin", a WHERE clause is appended to the SQL query.
How to expand a DynHtml pageDynHtml pages are expanded by the ExperSHOP Lite servlets: the user has nothing to do to expand the pages.
DynHtml statements$# $Action $Add $Append $AppendSql $Assign $Case $CheckNumber $ClearError $Cookie $Debug $DefVar $Div $Else $EndCase $Endif $EndLoop $EndSwitch $ExecSql $Exit $ExitLoop $ExpandFile $If $IfEe $IfEqual $IfError $IfFilePresent $IfGe $IfGt $IfLe $IfLt $IfNoResult $IfPresent $Include $LoopOnEnum $LoopOnFiles $LoopOnResults $Mul $SetCookie $Sub $Switch $System
Some formatting information can be specified, for example to format
numeric values: The format should be enclosed in parentheses, just after
the "$" character that delimits the variable (for example,
Numeric formats:
Any format supported by the java.text.DecimalFormat class. $(.00)Price$ $(##.##)TotalPrice$ Note that numeric formats can have unspecified effects when rounding numbers to integer values: particularly, (0) or (00) when applied to something else than integers.
If this is what you want to do, first round the values by using (Round),
(Ceil) or (Floor) formats.
Date formats: Other formats:
UrlEncode - URL-encode a value
(example:
DynHtml predefined variables$COOKIE$
The ExperShop session information, to be included in ExperSHOP URLs
(in HTTP links, using the <A HREF=...> tag). See also: $Cookie statement, for URLs invoked as HTML form actions. $\$
Displays a "$" character.
Data sets and data objectsA data object is equivalent to a database tuple, with attributes equivalent to database columns.
A data set is a set of data objects: for example, the result of a
database query, or the shopping cart seen as a set of items. There are two kinds of data sets: the expershop built-in data sets (like the Shopping Cart or the Shop's configuration file), and the run-time data sets (transient data sets, like database query results or string enumerations).
For example, ExperShop provides a built-in data object called
The Shopping Cart is also a data set: you can loop on cart items,
then display each item's characteristics (each item being a data object).
Of course, SQL queries are data sets, as soon as they have been
executed:
A parameter is a variable that will be considered an HTTP parameter in
the current page: it will be passed to actions if $Action is used.
(note: parameters won't be transmitted furter if the current page is
submitted as a form.
To append text to a previously defined variable or parameter, use the
A variable may be computed : $DefVar day (24 * 60 * 60) EnumerationsAn enumeration is a list of values separated by commas, or a continuous series of integers, or both; for example, you can define enumerations like this:$DefVar months Jan,Feb,Mar,Apr,May,Jun,Jul,Sep,Oct,Nov,Dec
$DefVar weekdays 1->7
The first one lists the months, the 2nd is equivalent to 1,2,3,4,5,6,7. It is valid to combine the 2 constructs: for example, $DefVar intervals 1->5,10->20
It is possible to loop on enumeration values, using the
$LoopOnEnum months mm Current Month is: $d:value$ $EndLoop $LoopOnEnum weekdays d Current day is: $d:value$ $EndLoopIn fact, an enumeration value can be considered as a data set, with tuples that contain only one column, called "value" (the reason for mm:value in the loop above).
It is possible to handle runtime errors using the
Example (most HTML forms should begin as follows in a DynHtml template):
<FORM METHOD=POST ACTION="com.expershop.lite.ExperSHOP"> $Cookie
Note that ExperShop does not use REAL cookies: in this document, "cookie" refers to session information stored on the server and associated to a session id. It is possible to store variables in the "cookie" information:
Define SQL request $DefineSql requestName sql-statement Append text to SQL request $AppendSql requestName text$AppendSql can be used in conjunction with "If... Else" statements, to complete an SQL request text. Note: If text begins with "AND" or "OR", the AND or OR string will be removed if text is the first condition of a WHERE clause. For example, appending "AND Price>10" to a query equal to "SELECT * FROM Items WHERE" will result in "SELECT * FROM Items WHERE Price>10". Then, appending "AND Price<100" will result in "SELECT * FROM Items WHERE Price>10 AND Price<100".
Execute SQL $ExecSql requestName Loop on query results $LoopOnResults requestName tupleName[(i,j)] ... $EndLoopIt is possible to add to the tuple name, the boundaries of the request, to loop from i to j. Attention, this option does not guaranty the order of the elements coming from the database. exemple : $LoopOnResults MyREQ myTuple(11,20) ... $EndLoop Display a column value (in a loop)
Handle no result case $IfNoResult requestName ... $Else ... $Endif Handle error $IfError ... $Else ... $Endif ActionsYou can execute an ExperSHOP Action from a DynHtml template, using the$Action statement (to learn more about ExperSHOP Actions,
see the DynHtml actions web page).
Syntax: Example: empty the shopping cart $Action com.expershop.actions.ESEmptyCart $IfPresent varname ... $Else ... $EndifExamples: $IfPresent FirstName $IfPresent customer:FirstName (in a loop)
$IfPresent filename ... $Else ... $EndifExamples: $IfFilePresent localFile.txt (in the current directory)$IfFilePresent /tmp/afile.txt (absolute path)$IfFilePresent f:FileName (in a loop)
$LoopOnFiles directory file Name: $file:name$, Extension: $file:ext$<br> ... $EndLoopThe directory may be relative to ESRootDir, or absolute (for example, if it starts with / on a Unix system).
$DefVar x 2.3 $CheckNumber $x$ $IfError ERROR: $x$ is not a number<br> $Else Ok<br> $Endif $ClearError
$DefVar a 1 $Add a 1 $DefVar b 2 $Div a $b$In this example, a=1, then we add 1 (a=2), then divide by the value of b (at the end, a=1).
$IfEqual varname value ... $Else ... $EndifExamples: $IfEqual City New-York $IfEqual FirstName "" $IfEqual FirstName $Name: $ $IfEqual customer:FirstName John (in a loop)Number comparisons
$IfEe varname 0 Zero! $Endif $IfLe varname 10 $varname$ <= 10 $Endif $IfLt varname $anumber$ $varname$ < $anumber$ $Endif $IfGe varname 10 $varname$ >= 10 $Endif $IfGt varname $anumber$ $varname$ > $anumber$ $Endif
$If ( expression operator expression) ... $Else ... $Endif"expression" can be : ($var1$ + 14)*3 + $var2$ "operator" can be a comparison operator, or a logical operator. Comparison operators are: < > <= >= = <> !=Logical operators are: && (logical and) || (logical or) ! (logical not)Parentheses can be used to group expressions. For example, the following construct is valid: $If $current$ >= $min$ && ! ($current$ > $max$) Current value looks ok. $Else Current value is out of range. $Endif Exit$ExitLeave the page immediately. $ExitLoopLeave the current loop immediately.
$Switch var $Case val_1 ... ... $EndCase $Case val_2 ... ... $EndCase $EndSwitchDepends on the expression value, the appropriate case is executed.
$ExpandFile filepath $ExpandFile is different from $Include: for example, a variable or an SQL query defined in the expanded file will no longer be accessible when back in the original file. filepath is relative to the directory where the current template is located.
$Include filepath $Include is different from $ExpandFile: for example, a variable or an SQL query defined in the expanded file will be accessible when back in the original file. filepath is relative to the directory where the current template is located. $System command $System executes a system command: the command output, if any, is displayed on the output HTML stream. For example, to list the files in /tmp on a Unix system: <pre> $System ls -l /tmp </pre> $Debug textDisplays text on the standard output, for debug purposes. Examples: $Debug Hello World! $Debug LastName = $LastName$
$# Comment |