Advanced XPages : Debugging Scoped Variables

Probably one of the most useful features
in XPages has to be the scope variables, with proper planning you can really
make good use of them and eliminate the need to store temporary values
in backend notes documents. As I showed in a recent blog entry
you can put anything into a scope variable, including a hashmap and you
can then run a repeat control off the hashmap. Well the scope variables
themselves are also hashmaps so why not use the same technique to see what’s
in them.

There are four scope variables that
you can use, applicationScope, sessionScope, requestScope and viewScope.
To make it easier to debug an application that is using scoped variables
I have created four new custom controls, one for each of the four scoped
variables. The code in the custom controls is simple.

<?xml version="1.0"
encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"&gt;
<xp:panel id="applicationVars" styleClass="debugPanel">
<xp:table styleClass="debug">
<xp:tr>
<th>Variable Name</th>
<th>Variable Content</th>
</xp:tr>
<xp:repeat id="varRepeat" rows="30" value="#{javascript:applicationScope.keySet();}"
var="scopeData">
<xp:tr>
<xp:td>
<xp:text escape="true" id="varName" value="#{javascript:scopeData}"
/>
</xp:td>
<xp:td>
<xp:text escape="true" id="varValue" value="#{javascript:applicationScope.get(scopeData)}"
/>
</xp:td>
</xp:tr>
</xp:repeat>
</xp:table>
</xp:panel>
</xp:view>

For the other custom controls you just
need to replace applicationScope with the other scope variables.

Using your new custom controls is easy,
just add them to the bottom of any page where you need to keep an eye on
the scoped variables. If your only using the sessionScope on a page then
you just need to add that custom control, if your making use of the requestScope
then just include that custom control.

I also like to create a new xPage in
my applications called ‘debug’ where I put in the custom controls for the
application and session scopes for easy access to them.

Don’t forget to remove ( or hide ) the
debug info before releasing your application.

Advertisements
Tagged with: , ,
Posted in None
One comment on “Advanced XPages : Debugging Scoped Variables
  1. Nice one. Leave the controls there but only show them when a session variable “isDebug” has the value “boolean true”. Then you can switch on debugging in a runtime environment

    Like

Comments are closed.

Archives
%d bloggers like this: