Sean Cull

SNTT : XPages onclick Ghosts in the machine 

Sean Cull  March 18 2010 10:18:13

For some time I have been convinced that there is ghost code in my Xpages applications. Being new to Xpages I often rework my approach to things and it seems as though my old code was still running  even though it had definitely been changed !

Another part of this phenomenon is that I have been convinced that onclick events in links have been firing on page load. This usually happened in the early hours adding to my belief that it was a ghost !

Well Keth Strickland made a post a few days ago that made me think it might not be just me. He described how if you edit the onclick property of a link in the "All Properties" tab the code would fire on page load.

Investigating further I found that the problem was two fold. Keith is right, it does fire but it is also possible to end up with two sets of code for the on-click event as the screen cast below shows.

1) Add some code to the on-click of a link via the events tab
2) save the document
3) reopen the document and you see the same code in the all properties tab for the link
4) modify the code via the events tab ( in this case change "2" to "x" )
5) save and close the document
6) re-open the document and you have two different sets of code, one of which also happens to run on page load

I had to make a screen cast to prove I wasn't mad.







 8.5.1  Dev Tips  Show-n-Tell Thursday  XPages  Lotus 


1Paul Hannan  3.18.2010 12:33:27  Looks like a designtime issue...

This looks like a design time issue what we'll investigate.

p.



2Vince Schuurman  3.18.2010 14:35:21  Use the Force..uhm... the source

Setting both an event and an onclick event on the same element, gives some weird results.

Best option to prevent 'ghosts' from appearing is to always check your code in the source pane.



3Keith Strickland  3.18.2010 18:06:38  Something else of note...

Glad I could help maintain your sanity!

When I was experiencing this issue I got to looking at the source for the link. It seems when you edit the onclick event from the All properties tab, another tag gets put within the link tag so you end up with this:

<xp:link escape="true" id="whatever">

<xp:this.onclick>Your onclick code here</xp:this.onclick>

<xp:eventHandler event="onclick" submit="true" refreshMode="complete"><xp:this.action>Your onclick code here </xp:this.action></xp:eventHandler>

The <xp:this.onclick> tag shouldn't be there. This behavior is repeatable every time you edit a link's onclick event from the All Properties tab. To fix the issue of the code within <xp:this.onclick> running at page load, just remove this tag and it should start operating as you would expect it to.





Please leave a comment


Subject:
   
Name:
E-mail:
 
Comment:  (No HTML - Links will be converted if prefixed http://)
 
Remember Me?