Category Archives: Dojo

How to compress an ICN Plug-in

Disclaimer: so I started this draft months ago, and apparently for months now, my main job has been taking all my time, so instead of keeping it as a draft, I thought I would just release this. Keep in mind it might not be perfect, but hopefully it can still help others. I’ve been using kind of the same process for months on production and our plugins work all fine.

Here is a long due article: how to compress/shrink and build production-ready plug-ins. The documentation is quite sparse about that, I found this forum post and of course there is the official Dojo documentation, but although it will help you build a product including what you need from Dojo, this doesn’t really explain how to build your plug-in so it does not include Dojo at all, since in our case it’s already part of ICN.

In this article, I will explain how to automate all the process using Gradle build, unlike the forum post I linked above which is providing an ant build to do this. Both are perfectly valid but as you can see in my open source plug-ins hosted in the IBM ECM GitHub, I’m fond of Gradle 🙂
Continue reading

Dojo constraints documentation

I couldn’t find any proper documentation on the constraints object we can use in Dojo to validate Text, Number and Date field, especially for ValidationTextBox. So here is what I gather or figured out from Dojo’s code.

ValidationTextBox:

The documentation says “user-defined object needed to pass parameters to the validator functions“, but actually that’s not true. This actually will never be used, except if you set a pattern abeing a function (this.pattern). If you do that then the pattern function you gave will be called on every validation with the constraints object as parameter, which can be anything since you are the only one using it in your function. The pattern function must return a String. Of course this.pattern can also be a simple pattern as a string, then constraints becomes useless and won’t be used. Example:

this._myValidationTextBox.set('pattern', function (constraints) {
    return constraints + '.*'; // For instance my input must start with my constraints
});
// OR
this._myValidationTextBox.set('pattern', constraints + '.*');
// Are exactly the same, but using the combo pattern function and
// dynamic constraints you can have a more dynamic behavior

I guess this could be used for complex scenarios where validation need to be more dynamic and we on;t want to change the pattern every time. Although I’ve never got to use it.

NumberTextBox:

Actually they put some documentation under the NumberTextBox documentation, so I won’t bother rewriting what they already wrote.

DateTextBox:

And the documentation for this one is here.

Using an external JavaScript (not Dojo module) in your ICN plugin

Sometimes you need to use an external JavaScript libraries in your plugin, because you don’t want to reinvent the wheel. Problem is that often those libraries are not Dojo modules. So how to use them in your dojo class?

Well that’s simple, dojo provides an generic script injection mechanism. Everything declared in the external script will be available in your class. Code is the following:

require(["http://host.com/stuff.js"], function(){
    // Everything declared in stuff.js is available here
});

You can link to an http location, or relative location into your project, for instance /application/stuff.js.

Now how to use that in your plugin? You can place your JavaScript file in another application or a CDN to refer it with an http protocole, example:

require(["http://host.com/application/stuff.js"], function(){
    // Everything declared in stuff.js is available here
});

Or you can leave the file in your plugin so everything is embedded when you deploy:

require(["plugin/MyPluginID/getResource/jszip/zip.js"], function () {
  // Here I can use the variable zip
});

Continue reading

Get started with Selenium

Last post of a three posts series about testing, after Unit Testing and Integration Testing, let’s talk about UI testing.

Introduction

Selenium is a Browser driver, basically it does what you would do if you were manually testing, i.e. clicking, looking for elements, selecting, scrolling…, except it does it alone, and can do it for hours without a break, every night…

How it works is quite simple, you are targeting DOM elements (or node, or WebElement, or any name you would like to call them) with selectors, and then you can do various operations on those like a user would do: wait for them to be present, to be visible, to be clickable, click on them, drag and drop something, enter information in a text field, …

Keep in mind that Selenium does the same thing that you would do. So if an element is not visible on the page and you would scroll to catch it before clicking, you have to do the same with Selenium, or it will throw an exception saying the element is not clickable because it is out of the view, which makes sense.

This article is an introduction to Selenium, if you want more applied examples for ICN and Dojo, you can read this post, but I would recommend you to read this one first to get familiar with Selenium.

Get started with Selenium

Continue reading

Proper asynchronous with Dojo

Not long ago, I was not really dealing as I should with asynchronous development in javascript. For instance, when I had to launch several asynchronous process and wait for them all to all complete, I was using a counter and decreasing it in the callback method until 0. Coming from the Java world and being use to synchronize/join/notify which make this so easy, I thought it has to be something better than this. And of course like always with Dojo, there is.

The solution lies in the dojo/Deferred, dojo/promise/Promise and dojo/promise/all classes.
Continue reading