332 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Jobs | Twitter | Bookmarks | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
Arguably the most dangerous thing you could ever do in XPages – let other people use your eval() in their SSJS
Tue, Jun 18th 2013 162
EXTJS in XPages #12 – Counting categories with Grouped columns
Tue, Jun 18th 2013 77
Editing and testing your XPages CSJS “in real time” using Chrome Developer Tools
Wed, Jun 12th 2013 125
Adding a new browser to the XPages “Preview in web browser” menu
Tue, Jun 11th 2013 161
EXTJS in XPages #11 – Grids with Locked Column(s)
Sun, Jun 9th 2013 134
Getting rid of pointless white space page separators in MS Word
Wed, Jun 5th 2013 127
DCLUG – June 13 – Darren Duke – I Have a Traveler Server – Maybe I Should Secure it Some
Mon, Jun 3rd 2013 156
Top 10
Make your XPages more maintainable – JavaScript Callback functions
Sun, Apr 28th 2013 563
Coolest Error Message ever – Anti-Folder views !
Thu, Apr 4th 2013 462
Server-side HTML vs. JS Widgets vs. Single-Page Web Apps – the XPages version
Mon, May 13th 2013 422
Someone is having a laugh right?
Fri, May 24th 2013 370
Webinar – jQuery: The World’s Most Popular JavaScript Library Comes to XPages – April 23rd
Mon, Apr 1st 2013 354
Domino R9 – now FIPS 140-2 compliant – necessary for doing business with the DoD
Thu, Apr 4th 2013 327
Webcast: jQuery The World’s Most Popular JavaScript Library Comes to XPages – now on YouTube
Fri, Apr 26th 2013 308
DCLUG April 24th – Getting Started with XPages
Wed, Apr 17th 2013 300
Writing a single library for SSJS and CSJS validation – failed attempt #1
Sun, May 19th 2013 295
JavaScript variable hoisting
Wed, May 1st 2013 289


Don’t believe the HTML – timing is everything in XPages CSJS
MarkyRoden    

So having made v2.0 of my TypeAhead control I am rapidly moving towards the next iteration making it easier to implement and not have to add functions to the fields in the designer. This becomes especially arduous if you have multiple TypeAheads in the same form and you want to add this capability to all of them.

The plan is to use a jQuery or dojo selector to get a handle on all the TypeAhead fields on the form and add the necessary function calls to each of them in one simple script library. (Because this is currently a capability without jQuery I am sticking with dojo, more verbose as it is)

So I created multiple TypeAhead fields (Copy/Paste) on the same XPage and looked at HTML to find out the selector I would need to create. I right click on the web page and view source and the out of the box HTML looks like this (pretty simple right..?):

<span
	id="view:_id1:_id2:_id30:_id43"
	dojoType="ibm.xsp.widget.layout.data.TypeAheadReadStore"
	jsId="view__id1__id2__id30__id43" mode="full">
</span>
<input type="text"
	id="view:_id1:_id2:_id30:inputText1"
	name="view:_id1:_id2:_id30:inputText1"
	class="xspInputFieldEditBox"
	dojoType="ibm.xsp.widget.layout.TypeAhead"
	store="view__id1__id2__id30__id43">
<br>
<span
	id="view:_id1:_id2:_id30:_id48"
	dojoType="ibm.xsp.widget.layout.data.TypeAheadReadStore"
	jsId="view__id1__id2__id30__id48" mode="full">
</span>
<input type="text"
	id="view:_id1:_id2:_id30:inputText2"
	name="view:_id1:_id2:_id30:inputText2"
	class="xspInputFieldEditBox"
	dojoType="ibm.xsp.widget.layout.TypeAhead"
	store="view__id1__id2__id30__id48">

So foolishly I thought – we need a simple attribute selector which will select attribute dojoType is like TypeAhead.

(I always start with changing the CSS as an easy indicator that I have a handle on the element)

	dojo.query('input[dojoType$=TypeAhead]').forEach(function(node){
   		dojo.style(node, {"border" : "2px solid red"})
 	 });

The Problem

I get a big fat nothing..

The most boring picture in blog history

Probably the most boring picture in blog history

So then I pulled up firebug to make sure I wasn’t being stupid, and sure enough I was…..it is not like I have already written about this before or anything….In firebug the actual DOM looks like this:

Right Click on the field and view in firebug

Right Click on the field and Inspect Element with firebug

 

Looking at the DOM within Firebug reveals Marky's stupidity

Looking at the DOM within Firebug reveals Marky's stupidity

Oh DUH – it is a dojo widget (remember) and once the page is loaded, dojo does some major DOM manipulation to create the functionality. This is actually a really nice demonstration of how XPages and dojo work in tandem. XPages creates some fairly innocuous HTML and dojo tranforms it into considerably more complex and voluminous HTML.

So looking at the DOM we have a problem because the final field which is created (that I want to get a handle on) does not have anything indicating that it is a TypeAhead and how can I “select” this out without adding client side events in the XPage….

The Answer

The trick is to execute or “selector” before the dojo widget takes over and messes up the DOM. Instead of adding the code to the onClientLoad event (which is also when the dojo widget magic is triggered) we need to add it to a script block inside of the HTML – before the page has finished loading.

This is a subtle yet important timing detail during the rendering of HTML pages. You can add a script tag to an HTML page and have it execute before the page is rendered to the user, but it can only take action on what has already been “loaded”…this is also why dojo and jQuery are usually triggered when the HTML document is finally loaded – to make sure all the necessary fields are “loaded” on the page.

In this case we are going to add the script block right at the end of the XPage to make sure that everything we are looking for is “loaded” before we act on it. The script block is added at the bottom of the XPage after all the fields. This will execute before the onClientLoad event.

Adding an in-line script block at the end of the XPage

NOTE

I am being very specific in the selector to only select INPUT (input) with Attribute dojoType ([dojoType$]) which ends in TypeAhead – see here for more information on dojo selectors

And looking at the Sourcecode you can see the script is the last thing on the page before closing </the xp:view>.

	<xp:scriptBlock id="scriptBlock1">
		<xp:this.value>
		<![CDATA[
			dojo.query('input[dojoType$=TypeAhead]').forEach(function(node, index, arr){
   				dojo.style(node, {"border" : "2px solid red"})
 			 });
		]]>
		</xp:this.value>
	</xp:scriptBlock>
	</xp:view>

This time we get a much more satisfactory result:

Selecting the elements before they are manipulated by dojo

Selecting the elements before they are manipulated by dojo

 

But wait – there’s more to this that meets the eye….

What is also interesting to note is that the styling applied to the INPUT field before the dojo widget has it’s way with the HTML is retained….but it is NOT applied to the INPUT anymore..not even close…..

Don't trust the HTML

 

Because of this, I am not sure at this point if I am going to be able to add the timing handlers for the TypeAhead – it will be fun finding out though, watch this space….

 




---------------------
http://xomino.com/2012/03/23/dont-believe-the-html-timing-is-everything-in-xpages-csjs/
Mar 23, 2012
71 hits



Recent Blog Posts
162


Arguably the most dangerous thing you could ever do in XPages – let other people use your eval() in their SSJS
Tue, Jun 18th 2013 7:18p   Mark Roden
In this article I will discuss the power of the JavaScript method eval() and demonstrate how your inappropriate usage of such could bring down your entire organization – yeah it is THAT dangerous…. Introduction In JavaScript the eval() method has long been known as extremely powerful and also extremely dangerous. It turns a string into an executable piece of JavaScript code. It can turn string  into JSON arrays: var str = '[{marky: "genius"}, {brad: "blog monster"}]' eval [read] Keywords: xpages database interface javascript server
77


EXTJS in XPages #12 – Counting categories with Grouped columns
Tue, Jun 18th 2013 5:31a   Mark Roden
In this article I will demonstrate how grouping can be added to the EXTJS grid within your XPage and how the number of rows within that group can be totalled and displayed to the user. EXTJS in XPages series Here are links to all of the previous articles in this series EXTJS in XPages #11 – Grids with Locked Column(s) EXTJS in XPages #10 – Grid Row Expander plugin EXTJS in XPages #9 – Infinite scrolling rebooted and reborn – v4.2 BufferedRenderer EXTJS in XPages #8 – Selecting data fr [read] Keywords: domino notes xpages database
125


Editing and testing your XPages CSJS “in real time” using Chrome Developer Tools
Wed, Jun 12th 2013 2:23p   Mark Roden
In this article I will demonstrate how you can make live changes to your CSJS using firebug and chrome deveveloper tools and figure out where your bugs are happening before committing them to your XPages database. Introduction  First rule of thumb – put as much of your XPages Client Side JavaScript (CSJS) in a JavaScript script library as possible. The reasons are compelling and simple: Separation of code makes for much easier maintenance Changing CSJS libraries required a CTRL-F5 to v [read] Keywords: ibm script library xpages application database javascript xml
161


Adding a new browser to the XPages “Preview in web browser” menu
Tue, Jun 11th 2013 3:06a   Mark Roden
I wanted to add Chrome to my list of browsers which I could preview my XPages in and I went digging in the preferences and found out how in File > Preferences under the general section there is a “Web Browser” option where you can add a new one Then I had to find where Chrome was installed (obviously change UserName to your own path) C:UsersUserNameAppDataLocalGoogleChromeApplicationchrome.exe Added it and there you have it – now in my menu [read] Keywords: xpages application google
134


EXTJS in XPages #11 – Grids with Locked Column(s)
Sun, Jun 9th 2013 6:51p   Mark Roden
In this article I will highlight a grid column property which allows the developer to lock the columns on an EXTJS grid in a similar fashion to freezing a frame in excel. EXTJS in XPages series Here are links to all of the previous articles in this series EXTJS in XPages #10 – Grid Row Expander plugin EXTJS in XPages #9 – Infinite scrolling rebooted and reborn – v4.2 BufferedRenderer EXTJS in XPages #8 – Selecting data from the grid and opening a document EXTJS in XPages #7 – Doing an [read] Keywords: xpages database
127


Getting rid of pointless white space page separators in MS Word
Wed, Jun 5th 2013 2:17p   Mark Roden
Thank you Simon Reid ! You are looking at a word document and it is a pain to move from one page to another because of the margins and a separator between each page Simple fix – mouse over the separation and double click How did I not KNOW ABOUT THIS?? And even better with short pages with a break in them Productive !! [read] Keywords:
156


DCLUG – June 13 – Darren Duke – I Have a Traveler Server – Maybe I Should Secure it Some
Mon, Jun 3rd 2013 10:31a   Mark Roden
This month we are delighted to welcome Darren and Lisa Duke of STS Inc. in Atlanta who are travelling to DC to present at the meeting ! Not only is Darren one of the most recognized names in the IBM Notes Domino community he is also a really entertaining speaker. Even if you are not into Traveler, you should definitely come, be entertained and learn something new. For more information on Darren – check out his linkedin page and if you want to talk Traveler while him and Lisa are in town &# [read] Keywords: domino ibm lotus lotusphere notes traveler bes blogger community google iphone linkedin podcast security server
97


OpenNTF Webinar – Getting Started with XPages – Tomorrow – 06-04-2013 10:00 EST
Mon, Jun 3rd 2013 9:19a   Mark Roden
Tomorrow I have the honour of speaking with my mate Dave Leedy and presenting the second in the OpenNTF webinar series - Getting Started with XPages Dave and I are going to go through a lot of information in a short period of time. The intention is to make the transition to XPages seem less scary, provide you information you need to know when making the transition and help you through the process. This conversation is open to all developers of all skill levels and I encourage community members [read] Keywords: domino ibm xpages community openntf password




188


Writing a single library for SSJS and CSJS validation – first success
Wed, May 29th 2013 6:49p   Mark Roden
The other day I wrote about my failure to realize that CSJS and SSJS libraries shalt not cross  during my attempt to write a single library for CSJS and SSJS validation code. Not to be out done and with some great suggestions from the wonderful Sven Hasselbach I trucked on into the next attempt. Parameterized development I first met this concept a few years ago. I was working on an application created by John McCann, and all the script routines for a suite of applications were sorted in notes [read] Keywords: domino lotus notes script library application applications database development firefox java javascript password security server xml
191


The original DBIcon image path is stored in the database
Tue, May 28th 2013 7:37a   Mark Roden
I noticed the following as it popped up in my DDE search for “iPad” – something just to be aware of. Don’t upload the DBIcon from a path you would consider inappropriate – it remembers [read] Keywords: database




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - Mobile Edition