198 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 6
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 4
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 4
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 5
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 10
Leaving the yellow bubble for a while
Sun, Jun 7th 2015 2
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 5
Top 10
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 10
Displaying fancy loading indicator while loading AJAX
Fri, Nov 11th 2011 8
XPages: Handling disabled Checkboxes
Thu, Mar 26th 2015 8
Creating a test environment: the easy way
Tue, Jun 3rd 2014 7
Get rid of the agent property “Target documents – all new & modified documents”
Tue, Jan 3rd 2012 6
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 6
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 5
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 5
3 XPages hints #2
Wed, Apr 30th 2014 4
Resolve time difference in hours and minutes of two date/time values
Wed, Aug 17th 2011 4


3 XPages hints #3: Homepage and Performance improvements
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Frederic dehedin    

Finally another blog post :-) hope these 3 hints will help you or will help you some day in the future.

In this series of XPages hints i included also a NSF File in which the described hints are implemented. But beware, it is not a design highlight :-) i wanted to keep it as simple as possible. The Extension Library is needed to run the examples (from openntf.org or the included version in Domino 9.x).

Hint 1: Always define a home page

Usually every applicatino has 1 point of entry, a homepage. This can be set in the Database Properties for the Notes Client and for Web Access. For the Web Access it works, kind of.. the XPage setted in the settings will open, but this setting has a serious drawback: it opens the application with the URL: “host/directory/database.nsf” instead of “host/directory/database.nsf/myxpagehome.xsp”. So relative urls for images, javascript and css files might not work when opening the application with the “.nsf” ending. As soon the user switches to another XPage, these resources work again. In order to prevent this, it’s a good practice to have always a “home.xsp” XPage, and this XPage will redirect the user, server side, to the actual entry page.

This is a way how you can achieve this:

1. Create a Managed Bean “ApplicationController”
Create a new Java Class and create a function which gets the XSP Context and trigger it’s redirectToPage method. Let’s say we want the XPage “xpageshints3.xsp” to be the first page to open, when the application loads, so we set the REALHOMEPAGE constant accordingly.

package ch.fdehedin.controller;

import java.io.Serializable;

import javax.faces.context.FacesContext;

import com.ibm.xsp.designer.context.XSPContext;

public class ApplicationController implements Serializable {

	private static final long serialVersionUID = 1L;
	private static final String REALHOMEPAGE = "xpageshints3.xsp";

	/**
	 * getting the XSP Contect and redirect
	 */
	public void redirectToRealHomePage() {
		try {
			this.getXSPContext().redirectToPage(REALHOMEPAGE);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public XSPContext getXSPContext() {
		return XSPContext.getXSPContext(getFacesContext());
	}

	public FacesContext getFacesContext() {
		return FacesContext.getCurrentInstance();
	}
}

2. Register this class as a Managed Bean in the faces.config. We can even use the “application-scope”, since we need only 1 instance, but consider using the “session-scope” and you can use this technique to have user role dependant home pages.

<managed-bean>
 <managed-bean-name>applicationController</managed-bean-name>
 <managed-bean-class>ch.fdehedin.controller.ApplicationController
 </managed-bean-class>
 <managed-bean-scope>application</managed-bean-scope>
</managed-bean>

3. Create a “fake” XPage homepage and call the “redirectToRealHomePage” function. Let’s name this page “home.xsp”

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" beforePageLoad="#{applicationController.redirectToRealHomePage}">
</xp:view>

4. Register the newly created XPage in the Database Properties

database-properties-homepage

Now you’re ready to go.. call the database with the “**.nsf” url, and the home.xsp will automaticaly redirect to your real homepage.

Another way to achieve this is to manipulate the Internet Site Documents on the server, but personally i prefer the above method described.

Hint 2: Use Dojo Dynamic Content Control to boost your XPages performance

With the Dojo Dynamic Content Control you can decide that some time consuming elements of you XPage are loading after (asynchronous) the main XPages has been loaded and displayed in the browser.

IBM Connections uses this technique pretty often: The main parts of a page is being loaded instantly and other parts are being loaded later with a spinning circle symbol. So the page is actually not loaded faster, but you can decided that important parts are being loaded instantly and not so important parts are being loaded later. This will result in a better user experience (the page loads emotionally faster)..

So what’s the use case?
In one of my recent XPages Applications i was working on, the main Form was pretty simple, but on the sidebar on the right of the form we had to display depending data from several other databases and some of them are pretty large.. So when the form was loaded, it always took some time due to the lookup to the other databases. In this case the Dojo Dynamic Content came pretty handy: we decided that the data from the other databases will load asynchronous with the Dojo Dynamic Content while the main Form loaded instantly.

I prepared a little example:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
 Wait until the following content has loaded:
 <xe:djContentPane id="pnlContentPange" partialRefresh="true"
 loadingMessage="loading">
 <xp:text escape="true" id="computedField1">
 <xp:this.value><![CDATA[
 #{javascript:var startTime = new Date().getTime(); // get the current time
 while (new Date().getTime() < startTime + 3000){};return "finished loading!"}
 ]]></xp:this.value>
 </xp:text>
 </xe:djContentPane>
</xp:view>

Result:

loading-contentpane

 

Hint 3: Use Java Managed Beans instead of ServerSide Javascript for better performance

Maybe many XPages developers might moan up by this title.. Javascript is totally fine, i love JQuery and i started to like DOJO, but for me it’s not the programming language to pick when it comes to complex applications with a lot of business logic. Don’t get me wrong, if you’re a Javascript crack, doing reusable components, centralise the code in libraries, than that’s totally fine.

I’ve seen application containing XPages with over 2’500 lines of code(!) with totally mixed XPages XML, inline CSS, ServerSide and ClientSide Javascript functions and i do not want to be the poor soul who has to enhance or maintain this mess. Sooner or later applications like this will run into serious problems in terms of maintainability and performance.

When we speak about performance: i did a little comparison with 2 buttons doing exactly the same thing: they simply feed a string array with 3’000’000 entries.. Let’s start the race:

SSJS_Java_Comparison_Performance

Java Managed Bean: The method is in a managed bean, which resides in request scope. It runs not even 1 second on my machine (fairly old Macbook Pro with a Windows VM). When the bean would be in session or view scope it might run even quicker..

ServerSide Javascript: The method is inside the XPage. It runs roughly 13 seconds (!).. sometimes it even ran into the partial refresh timeout and i had to extend it.

Download

Download the examples as NSF File.

Download Lotus Notes nsf File



---------------------
http://www.fdehedin.ch/579/3-xpages-hints-3-homepage-and-performance-improvements
Feb 29, 2016
6 hits



Recent Blog Posts
6
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 4:17p   Frederic Dehedin
Recently i studied for the Java SE 8 Programmer I Exam (Java OCA for short) and was glad that i passed it on the first go. Although i’ve been practicing programming in Java several years, i decided to sustain my practical knowledge with some theoretical background and i’m happy to share my experience in this blog […]




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition