Inserting HTML Into Reports
Inserting HTML Into Reports
|
Logi Info, Logi Report
v10.0 - 29 Mar 2010
|
The Logi Server Engine generates HTML and Javascript when it processes a Logi definition, but developers may find that they need to insert their own HTML code directly into a Logi report. Two elements, Include HTML and HTML File, are available to accomplish this and they're discussed in this document. Topics include:
About Inserting HTML
The "source code" of a Logi definition is an XML document, which is processed by the Logi Server Engine. However, under certain circumstances, Logi developers may want to insert their own HTML code directly into a Logi report. Three common circumstances include adding <META> information, adding <SCRIPT> content, and embedding external HTML documents in your report page.
For example, the document you're reading right now is actually a separate, external HTML file that has been embedded into the DevNet site page.
Requirements
HTML that's included into a Logi definition must be have properly-formed tag structures, and include all closing tags. For example,
If a complete HTML page is embedded, it can include <HTML> and <BODY> tags but they are not required.
Back to the top
Using the Include HTML Element
The Include HTML element, introduced in v9.5.169, allows you to insert HTML at selected points within your report definition.
This element can be placed in your definition as the child of a number of elements, such as Report Header, Body, Division, Data Table Column, Report Footer, and others. See the Element Reference entry for this element for a complete list.
In the past, developers have used a Label element, set to HTML format, for this purpose. However, feedback from developers indicated that this was a somewhat obscure usage, so the Include HTML element is now recommended for this purpose instead.
A simple example is shown above and the resulting HTML looks like this:
| |
<HTML>
<BODY>
<MainBody>
<SPAN><p>Here is my HTML</p></SPAN>
</MainBody>
</BODY>
</HTML>
|
Scripts can be entered here in the same way, using <SCRIPT> tags. If you double-click the HTML attribute name and open the Attribute Zoom window, it's easy to enter multi-line scripts, like the following example:
| |
<script type="text/javascript">
NagMsgTimer = function() {
setTimeout('ShowNagMsg()', 2*60*1000); /* delay 2 mins, in milliseconds, */
}
function ShowNagMsg() {
alert('Register your product now!');
setTimeout('ShowNagMsg()', 2*60*1000); /* delay 2 mins, in milliseconds, */
}
/* cause function NagMsgTimer to run when page is loaded */
if (window.attachEvent) { /* IE */
window.attachEvent('onload', NagMsgTimer); /* event name is case sensitive */
}
else { /* Moz, Netscape, Firefox */
window.addEventListener('load', NagMsgTimer, false);
}
</script>
|
This script will be included in the HTML and, because it attaches itself to the page load event, will begin to execute automatically when the page is loaded. To get the script to be inserted in the <HEAD> section, add your Include HTML element as a child of the Report (root) element in your definition; to add it in the <BODY>, make it a child of the Report Header or Body elements.
<META> tags can also be added to the <HEAD> section in the same way, by making the Include HTML element a child of the Report element.
Back to the top
Using the HTML File Element
The HTML File element allows entire HTML documents to be included within your Logi report definition. HTML files that will be included in this manner can be managed as support files and will be available from a drop-down list if they're stored in your application's _SupportFiles folder.
The HTML File element can be placed in your definition beneath a number of elements, such as Report Header, Body, Division, Data Table Column, Report Footer, and others. See the Element Reference entry for this element for a complete list.
If your HTML file has been added to the application in the _SupportFiles folder, then, in the HTML File element's Filename attribute, you need only specify the actual file name or select it from the drop-down list, as shown above. Otherwise, you'll need to specify a fully-qualified file path (on the web server), starting with a drive letter.
In the example shown above, the HTML File element is inside a data table column and its filename attribute is being supplied from a database query.
You can place script functions in an HTML file (with the proper <SCRIPT> tags) and use HTML File to include them in definitions; this can be useful if you want to include the same script functions in a number of Logi definitions but maintain them all in a single file.
Here are some key points to remember when working with HTML files with visible content and the HTML File element:
Caching Confusion
Files embedded with the HTML File element are cached at the web server. If you forget about this, it can cause great frustration when you edit the HTML content and then it doesn't appear to change in the report page! To abandon the cached content, you will need to delete the value in the Filename attribute, save and browse the page again, then re-enter the filename and continue testing. Or, if it doesn't affect anyone else, you can reset the web server.
Width Coordination
When embedding your HTML file in a report definition that you must pay close attention to widths. Possible parent elements, such as Column and Data Table Column, need to be wide enough to accommodate your HTML file; conversely, your HTML file may need to constrain its own width to fit inside the Logi report page. Coordination of widths is essential for a good result.
No Scrolling
A file displayed using the HTML File element will be shown in its entirety; its full length will be displayed, "pushing" anything below it down the page. There is no option to show a portion of it within a scrolling window. (To create a scrolling area for HTML content within a report, you need to use the Sub-Report element).
Stylesheet Interaction
The effects of style classes referenced in your embedded HTML document will be combined with those of the Logi report page containing the document. They will interact and this can have unexpected consequences as different classes vie for precedence. There is no hard-and-fast rule to follow concerning the use of style in this situation, but be prepared for the possibility that a little experimentation may be necessary to get things looking right.
Back to the top
Invalid XHTML Characters
The Logi Server Engine may generate errors if it needs to read a string of characters as XML and that XML includes un-escaped, invalid XHTML characters.
A primary examples of this is when AJAX-style requests are used, such as data table sorting or paging (when Ajax Paging = True has been set), or use of an Action.Refresh Element that includes a data table or other data object. In these cases, the XML data may be indistinguishable from XML tags and reserved characters.
This can also happen when HTML is included in a report definition using the techniques discussed earlier.
The most common culprit in this scenario is the inclusion of unencoded "&" characters. In situations like those described above, the application will fail and produce an error message that looks like a parsing error.
Replacing the "&" character with "&" is often an easy solution.
Back to the top