Thursday, September 20, 2012

Use "secret" XPages for controlling scoped variables

I run an XPages application used by multiple companies.  Some menu choices are only visible to system administrators and we often log in as those administrators to perform configuration and testing.

The problem is that sometimes we need to turn on/off other secret switches to help us with deeper application testing such as enabling/disabling debugging or showing/hiding menus that we only want to display when we are logged in and doing testing as a company administrator.  These menus are not visible to normal administrators so that rules out Roles.

To make this a bit easier on us I create On/Off XPages that I enter into the URL when I want to enable/disable a session scope variable on demand.  The XPage sets the session variable and returns us back the current XPage.

Not elegant but it really fits the bill.

Here is the code for a debugOff.xsp...we just enter it into the URL address whenever we need to disable the values and we use a corresponding XPage to enable the values.



<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

<xp:this.beforePageLoad><![CDATA[#{javascript:sessionScope.debugMode="No";
print("debugMode = Off")}]]></xp:this.beforePageLoad>

<xp:eventHandler event="onClientLoad" submit="true"
refreshMode="norefresh">

<xp:this.action>
<xp:openPage name="$$PreviousPage"></xp:openPage>
</xp:this.action>

</xp:eventHandler>

</xp:view>


Of course a Clever Person would make a single XPage to toggle the values on/off but I have to save my Clever Energy for more detailed tasks!