Script Resources in Xpages

Earlier today I was looking through some example of a javascript framework and in them they used <script> tags in the <head> of the html document.  I was trying to take the example and apply it into xpages, however I was having issues adding a script tag that had inner text into the head of an xpage, I wasn’t aware of how to do it outside of writing a custom ScriptResource.  However I reached out to a few experts and Tim Tripcony came through for me again and gave me the answer I was looking for.  The standard Xpages ScriptResource resource actually includes an attribute called “contents”  that writes the script out to the head tag.  I thought I would share here in case someone else was looking for a way to do it.

<?xml version=”1.0″ encoding=”UTF-8″?>
<xp:view xmlns:xp=”http://www.ibm.com/xsp/core”&gt;
<xp:this.resources>
<xp:script clientSide=”true”>
<xp:this.contents><![CDATA[alert(“This will display inside the script tag”);]]></xp:this.contents>
</xp:script>
</xp:this.resources>
</xp:view>

The above Xpage will render a tag inside the head tag like this:

<head>

<script type=”text/javascript”>alert(“This will display inside the script tag”);</script>

</head>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s