Tag Archives: XPages - Page 5

QuickTip: Get right path when autolaunching an XPage

If you are using relative urls to you resources you might have got the problem with dead images and resources that doesn’t load. The obvious choice is to add the full url to the images.

Snap181

The problem is often related to when you autolaunch an XPage on database open.

Notes Autolaunch Tab

But there is another way than adding the full url for the problem. You need to add a trailing slash to your path then everything will work as expected again. And using these few javascript lines added to your front page onload event or in a script on the page will fix the problem.

var h=window.location.href;
if(h.indexOf(".xsp")==-1){
if(h.substring(h.length,h.length−1)!="/"){
 window.location.href+="/"

}}

Start using the New SSJS Debugger in Designer 9

My first show is on Notes in 9 check it out.

SSJS Debugger Demo in Notes in 9

Check out my two post last year regarding a SSJS Debugger  –> Link

Conditional breakpoints was one of the suggestions that was voted up as a function in the debugger and we get that. I don’t know if someone at IBM did read this and the feature is there because of the post but I like to think so 😉

Snap113

If you have any great tip regarding debugging in Designer 9 please feel free to comment.

Filter and hide closed databases

I had some feedback on the designer some weeks ago, that it would be good to filter away closed databases in package explorer. This does already exists in Designer today, Kudros to Dan O’Connor that showed me this. (The icon has changed from 8.5.3 to Designer 9)

Filter1

And uncheck Closed projects

Finter2

Now your package explorer is much cleaner and you can find you databases alot faster.
The closed project does also show up directly in the menu so you easily can toggle it.
Filter Closed projects
You can also use worksets here to get better filtering of databases and on disk projects

Document Locking in XPages

People editing documents at the same time can be a big pain for the developer resulting in unwanted problems in an deployed application. To handle this problem I created a managed bean DocLock to handle the problem. The managed bean stores the username and an id each time the users edits a document. If another user tries to edit the document, you can block the user from entering edit mode. 

To implement the managed bean in your own database is very simple, Copy the java class and add the managed bean setup into faces-config.xml ( check the supplied readme file)

The project is released on Openntf –> Link

Snap83

Enjoy getting less document conflicts.

What a year for XPages

The year started early with the release of Upgradepack 1 for domino.
We have got 3 fixpacks for domino and 6 releases of the extensionlibrary.
And so much knowledge published as blog posts/applications/custom controls/code snippets.
What a year!
I think that 2013 will bring alot of good stuff to. With the release of Domino 9.0 and hopefully Upgradepack 2.

Happy New Year to everybody!

IBM Champion I’m honored

I’m one of the lucky ones that have been awarded IBM Champion 2013 for Collaboration Solutions.

All the Champions 2013

Thanks again IBM and congratulations to everybody else who got awarded. 

Preventing the XPages Dialog control to auto center

If you ever tried to use a XPage dialog control from the extension library on a mobile device. You’ll probably seen this behavior, the dialog is moving away each time you try to click on a button or a field in the dialog.

The trick to fix this is to force the dialog to a fixed location if you are on a mobile device with a small screen.

There are several ways to detect this:

check out this stackoverflow question how to detect iphone by CSS –>Link

You can use this xSnippet –> Link or this post by Keith Strickland –> Link

When you can detect this and depending on your approach place the following code in a stylesheet

or if you place it directly as a computed style on the dialog.

The following css properties is that makes the dialog to stop moving around. 

top:100px !important;
left:100px !important;

This will force the dialog to be placed at position 100,100 on screen. !important is a css property that forces an override of other properties set.

So what I usually do to fix this is add the xSnippet in a SSJS Scriptlibrary and add the following code as a computed style property on the dialog 

if(isIphone()||isAndroidCheck()){
return "top:100px !important;left:100px !important;"
}

Enjoy your mobile application 

Use the same datasource everywhere in XPages

When using custom controls there are several ways of binding fields to backend fields.

1. Create a datasource with the same name as the datasource you are using for the fields

(Warning! if you forgett to remove this when you are done you will get a replica conflict)

 

2. Pass the Datasource into the custom control and use the compositeData.propertyname[“fieldname”] to bind to the field. This article describes how to do this –>Link

 

3. Use a save function and retrieve the values from the fields and save the information to fields. This would also require a load function to populate the fields.

And there are probably several more ways of doing this, that is often the problem with XPages you get multiple ways of doing things and you don’t know the right way.

If often use number 1 when I’m creating xpages, the problem with this way is that if you have to add a new fields later you have to add the datasource again if you would like to use the simple binding dialog.

But there is another way, add a datasource with the variable name and properties as you main datasource. Go into source mode and add loaded=”false” to the data sources on you custom controls, you can still use the simple data binding and you will not get any replica save conflicts because this datasource isn’t loaded.

This is what you source should look: 


Hope this will help you get rid of some annoying replica conflict when you have forgotten to remove a datasource. Enjoy!

New version of my Tinymce Custom Control

I got an enhancement request from a user if it’s was possible to validate if the tinyMCE control had some text.
Because validation is implemented as a core property on XPage Controls this was a quick fix.  

One Tip i can give when creating your own custom controls is when binding computed properties, set the property how the compositeData property should bind to compute at page load, if the data shouldn’t update.
Some properties of controls require this. I don’t know if this is a bug or if it’s this is meant to work like this. 😉

I also built an XPage using the Form Table control to display how the validation looks like.

Check out the new version of the Tiny Mce custom control –> openntf project page 

Using RegExp to make field validation easier

There is alot of ways to validate fields. But if you ask me validating thru regular expression is very powerful because you can test for patterns in strings. You can test for valid email adresses, phone numbers or your required passwords.

Because regular expressions can be tested both on the client and the server using almost the same code you can do tests on the client side without doing round trips to the server when the user exits a field or perhaps while the user are typing.

Lets look at an example of an regexp

[a-z]+

This will check that the tested string contains letters in the interval a-z

(\d{5})

The above code will test so the string is five numbers.

This is very helpful because then you could test for a password pattern

((?=.*\d)(?=.*[a-z])(?=.*[A-Z]))

This will then test the string to contain a digit, a lowercase and an uppercase letter. Imagine testing this some other way, no thanks. To complete this we also need to test for length and that we do by adding this to the line .{8,14} this will test that the string is 8 to 14 letters long. So the complete string is then

((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,14})

This seams complicated you might say, Yes regexp can be complicated but then we have great resources online to just copy and paste regexp from. But test the regexp you copy from the web, they might not do what you want them to do 😉

The best regexp tester that I have found is Rubular

How to use Regexp with old school Domino and XPages

How do you use this in HCL Domino if you haven’t moved over to XPages yet, you could use this in client side javascript. And if you have moved over to XPages you can use this in Client side JS, Serverside JS and with a expression validator. I’m going to show you all these ways to validate.

1. Client side JS validation using RegExp

var field=document.getElementById("YOURFIELDNAME");
var data=field.value;
var re=/\d+/
if(re.test(data)){
   alert("Valid");
}else{
   alert("Not Valid");
}

2. Serverside javascript

The first Two lines changes from the client side script and also you need to write what should happen if the validation is true or not.

var inputText1= getComponent("inputText1");
var data=inputText1.getValueAsString()

var re=/\d+/
if(re.test(data)){
//do some stuff
}else{
//Do other stuff
}

3. validateExpression validator

The only thing diffrent in this validator than number 2 is that you return true or false when validation is done.

4. validateConstrain validator

This validator is used if you want to do a complete match of the value in the field using regular expression. My suggestion is that you start the string with ^( write you expression and end with )$ because then it’s easy to use a regexp tester when testing your regular expression this will tell the regexp engine that the string must validate as a line of text.

Update:

Check out this great post about how to create regex strings directly in the designer.

http://www.intec.co.uk/test-your-regular-expressions-in-domino-designer/#comment-1498