Visualforce and the Konami Code

January 11, 2012

So I promised to give details on my hidden, Konami Code triggered debug panel yesterday, so here we go…

Firstly, in your Visualforce page, you’ll need to pull in the Konami Code javascript from Google Code, like so :-

<script type="text/javascript" src="http://konami-js.googlecode.com/svn/trunk/konami.js"></script>

after which, we can tell it what action to trigger when the code is entered correctly :-

<script type="text/javascript">
konami = new Konami()
konami.code = function()
{
enableDebug();
}
konami.load()
</script>

where enableDebug calls back to the controller apex via an apex actionfunction :-

<apex:actionFunction name="enableDebug" action="{!debugOn}" rerender="debug />

This calls the server-side apex function called debugOn – note how it re-renders the debug panel on completion. This panel is defined as :-

<apex:pageBlock title="Debug" id="debug" rendered="{!isDebug}">
<apex:outputText value="{!debug}" />
</apex:pageBlock>

you can see a couple of things here. Firstly, the panel is only rendered if the value of isDebug is set to true. This value is toggled by the Konami Code. Secondly, it displays the contents of variable debug, which you can set to anything you like. I frequently use it to show the SOQL string I’m querying against

Having set up the VisualForce side of things, we need to implement the server-side callback function in our Apex controller for the page :-

public string debug {get;set;}

public Boolean isDebug {get;set;}

public void debugOn()
{
isDebug = !isDebug;
}

so now at any point in your code, you can store a string value in the debug variable and it will be displayed on the rendered page once you enter the Konami Code (and press Enter)


September 24, 2011

I am now spaced out with two wisdom teeth missing


Laugh a minute

May 25, 2011

Earlier in the week, I entered a free prize draw via the coffee vendor at the train station to win a pair of tickets to the local comedy club.  Got an email through today to say that I’ve won them – w00t!

The lineup :-

 Headline – James Sherwood  ”Elegant, intelligent stand-up, with regular  laughs to keep everyone satisfied.” Guardian

Support – Craig Murray – “Bloody funny” Jo Brand

Support – Luke Benson “one of the most instantly likeable personalities on the line-up. His punch-lines hit the targets… even more impressive was how he found a clear voice whatever style or subject of comedy he tackled.”  The Stage

Compere – Paul T Eyres – “Fantastic. I was laughing every 15 seconds” - (Sol Bernstein aka Steve Jamieson)


Weekend update

May 22, 2011

Busy weekend clearing the garden, or at least making a start on it. Night off last night, inlaws babysitting so out for a Nepalese meal.

Sunday more work in garden and now we’re off to a kids birthday with Elena, who is in her new party dress

20110523-055907.jpg


So long (Facebook) and thanks for all the fish

May 20, 2011

So I’ve killed off my Facebook account (again).  Fed up with it.  My musings will be here and on my tumblr blog


December 1, 2010

Why are VST plugins so prohibitively expensive?


November 12, 2010

There’s a rainbow inside your mind.


November 8, 2010

Time for Tubby bye bye…


November 1, 2010

Psytrance for my ears, Objective-C book for my eyes. Monday brain-load started….


October 28, 2010

Children should only be allowed one VTech toy, to prevent them all making irritating noises simultaneously.


Follow

Get every new post delivered to your Inbox.