dominoGuru.com
Your Development & Design Resource
XPages, Session Scope Variables, and User Agents in IBM Lotus Notes Domino Application Development
06/29/2010 04:15 PM by Chris Toohey
I've talked before about progressive enhancement in the context of application development and supporting multiple User Agents - be they the Lotus Notes Client, various Web Browser Clients, or even Mobile Devices like the iPhone, iPad, and BlackBerry! The idea is simple enough -- render unto the User Agent what works for that particular User Agent.
Who?
This tutorial is designed for novice / beginner level XPage application developers, and these techniques can be used in Lotus Notes Client, Web Browser Client, and Mobile Device Client IBM Lotus Notes Domino Application Development.
What?
This tutorial will walk you through creating an XPage that uses a Scoped Variable and returns that value -- the current User Agent -- to the UI.
I will follow-up this post with a more advanced use of this technique, specifically using the User Agent Session Scoped Variable to control the rendered content for an XPage application.
When & Where?
You will eventually use this technique to conditionally display XPage Controls. Consider, if you will, that each Control is a Subform on a Form Design Element.. The rendered parameter allows us to define conditions for when the given XPage Control is displayed... not until a Computed Subform on a Form Design Element. Unlike a Computed Subform, the rendered logic, there is a minimal performance hit when using multiple rendered Controls on an XPage.
This gives us the ability to write a single Design Element to address multiple Client Types while simplifying overall development maintenance.
Why?
Using this technique, you can choose to render the iWebKit Framework for WebKit-based User Agents (iPhones, iPads, BlackBerry OS 6 devices, Palm Pre, etc.) or BlackBerry OS 5 (or less) -friendly markup as needed.
You can provide specific User Agents with device/client-specific features and functionality, and with Session Scoped Variables, the "cost" of calculating the logic can be greatly reduced!
The Build
Going really simple here: I'm going to create the Scoped Variable
UA
that stores the text value of the User-Agent Header.
I'll then use that Scoped Variable in the UI of my XPage.
First, the XPage Source:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
pageTitle="Agent Smith Says...">
<xp:this.resources>
<xp:styleSheet href="/style.css"></xp:styleSheet>
</xp:this.resources>
<xp:this.afterPageLoad>
<![CDATA[#{javascript:
var exCon =
facesContext.getExternalContext();
var
request:HttpServletRequest = exCon.getRequest();
var UA =
request.getHeader("User-Agent");
sessionScope.put("UA",UA);}]]>
</xp:this.afterPageLoad>
<span id="useragent_content">
We've had our eye on you for some time now, Mr.
<xp:text id="useragent" value="#{sessionScope.UA}"
rendered="true">
</xp:text>
</span>
</xp:view>
I am defining my Session Scoped Variable UA
in the XPage
afterPageLoad Event.
I am then using the sessionScope.UA
in my ComputedText Control
to return in the XPage UI the current User Agent.
Simple.
With a little CSS and an Image Resource...
Now, this is a simple example, but after defining the Session Scoped
Variable UA
, I am able to use it in any context within my XPage
application while within that session.
Example / Demo Download
This application can be used in the Lotus Notes Client as well as in a Web Browser Client. Technically, it could be used in a Mobile Device Browser Client, but the 450x500 image of Agent Smith might not work unless you're running a device with a high-res screen.
Conclusion
I'll be using this very simply technique in follow-up posts to show you how the defining rendered Controls on the User Agent will allow you to create some really slick IBM Lotus Notes Domino XPage Applications.
If you have any questions -- or requests -- comment to this post or contact me at ctoohey@dominoguru.com.