Try to avoid the use of Jars design element

Lately I had pulled a new project to work on, a XPages application with a few external jar files.

When I tried to build the application it produced a lot of errors. The most annoying error was that classes could not found, and these classes are inside the external jar.

Mmmm… strange.

 

When I looked inside the application view in the Domino Designer I found the external Jars in the Jars section under code as Jar design element.

In the build path there was a reference to these external jars, but the path was changed to WebContent/WEB-INF/lib/external.jar.

 

Real strange…….

In the package explorer the lib directory under WebContent/WEB-INF was present but empty.

So the Domino Designer magically moves the external jar files under the hood to the correct location. Nice but it gave me a very strange feeling and lots of errors, because it could go wrong.

 

Get it working

I have removed all the references of the external jar file from the build path. Moved all the external jars in the Package Explorer from the jars section to the correct location, WebContent/WEB-INF/lib/. That location is the correct place where a Java server is looking for external jars, anyway so why not put them there immediately.

Build the application and gone where all the errors.

 

Move on

As I move more and more over to the J2EE world I get used to the real Eclipse and his perspectives and views. I ‘live’ in the package explorer and have not the luxury of an Application view with design elements. In Domino Designer I hardly use the Application view, everything I do on XPages development I do in the Package Explorer. More what you is what you get 😉

If you want to look around to other technologies and Java/J2Eee/Vaadin is your choice, get use to the Package Explorer and abandon the use of the Application View.

The same apply of the Java classes as for the jar files, put them directly on the right location in a directory under WebContent/WEB-INF/ and make this directory a source folder.

twittergoogle_plusredditpinterestlinkedintumblrby feather

Plugin updates: search and date format

Today I made a few changes to the Cloudant connnector and Jackson4XPages plugin.

Jackson4XPages

I added a new constructor of the JacksonWrapper, a boolean, to control the date format output in the JSON.

JacksonWrapper wrapper = new JacksonWrapper(datesAsTimeStamps);

By default it is true, so the output format is a Timestamp, but if you need a real date, pass false to the contructor

I committed the changes to the repository and updated the ReadMe.

 

Cloudant connector

I added a new connector to the plugin, the QueryConnector. In this new part there is the possibillity to actual search the Cloudant database. And have access to the indices.


//search the database
List<?> connector.getQueryConnector().search(final String searchIndexId, final Class<?> cls, final Integer queryLimit, final String query)
//To learn about the query syntax see, https://docs.cloudant.com/search.html

//To get all the indices

List<?> allIndices();

//To find documents using an index

List<?> findByIndex(final String selectorJson, final Class<?> cls)

I committed the changes to the repository and updated the ReadMe.

twittergoogle_plusredditpinterestlinkedintumblrby feather

A small update to my Multi language 4 XPages demo

Last week I have posted a demo database of my way to add multi language to a XPages application.

Today Patrick Kwinten pinged me on Slack about an 500 error he was hitting when he access the database from the browser.

After some investigation via Slack it the cause of the error was an external jar file which was in still, unused, in the database. The external jar was on the Build Path, but after removing from the Build Path it was still crashing. On stackoverflow I found the answer.

The external library was causing an reflection exception. There was no need for this external library, so no need to update the java policy file.

After removing the external jars completly from the database, the application was up and running again. Everyone happy 😉

I made the update to my demo database and commited to the Bitbucket repository of this demo.

Where are my Java classes

I also noticed that it is not common or the normal way, when using Java in DDE to store the Java classes in a Java directory which I created under WebContent –> WEB-INF and add the directory as source folder.

In my life outside the DDE/Domino world when building Java applications in vanilla Eclipse environments, it is the normal way, so I still use it in DDE. So for Java development I live in the Package Explorer.

packageexplorer

To find the Package Explorer. Goto Window –> Eclipse Views –> Packagage

javaclasses

So I encourage everyone when do Java development in an XPages, to use the Package Explorer and the Java classes in a folder under WebContent –> WEB-INF ( next make them a source folder ). When moving to other grounds, outside the Yellow bubble or doing more and more OSGi plugin development, it makes your life easier.

twittergoogle_plusredditpinterestlinkedintumblrby feather

XPages tip: Demo code for multi language support

Over time I wrote a few blogs about my way to support multi language in a XPages app.

  1. Control the labels in a XPage app

  2. Multi language support for labels

  3. add a new language to your app

Very nice, but I got requests about a demo db.

I created a demo database which is available as GIT repository on Bitbucket.

What’s inside

  • Load properties from a properties file, which reside in resource section of database
  • Load languages
  • Add new Language, which add also for this new language property documents.
  • Export of the default properties file to change in one time all the labels
  • Reimport the new language property file, expecting a certain format countrycode_countryname e.g. nl_netherlands.txt
  • When a language is removed, all the property documents for this language will also be removed
  • Language is stored in a userpreference document.
  • Set a default language, which is used as not language is available for the user.
  • I did not removed all the bootstrap fields, the theme and front end frameworks which is imported by Bower. So use it if needed.

Multi language 4 Xpages demo

Happy coding

twittergoogle_plusredditpinterestlinkedintumblrby feather

Update on my Cloudant connector for XPages

update

A few weeks ago I released a small OSGi plugin project which connect to Cloudant. More details, see my previous blog.

I have changed the plugin completly 😉

One of the reasons is to make it easier in the future to add new functionality. There are so much nice feature to be added.

What is new

  • I moved all the database related methods to the DatabaseConnector.
  • Moved all the document related methods to their own DocumentConnector
  • Added to the DocumentConnector a method to add an Attachment to a Document.
  • Added a Logging class.
  • Moved the xsp config files to their own package and changed the reference to it in the XspLibrary class.
  • Changed the library ID, found the XspLibrary in the library ID not very nice. It will be

    ‘nl.elstarit.cloudant.library’ to be looking for in the XSP properties of the NSF after it is installed in the Domino Designer

  • Fixed an issue which caused that the library ID not was showing at all in the xsp properties file.
  • Added a ConnectorResponse class which represent the Response which you get for example if you add an Attachment.
  • Added Java doc.

 

I have updated the repository on BitBucket and also updated the ReadMe file to represent the new structure.

twittergoogle_plusredditpinterestlinkedintumblrby feather

Cloudant-connector for XPages

ibmcloudant
At Engage I was triggered by a great session of Niklas Heidloff of all the goodies on BlueMix. He was mentioning Cloudant, which is used for Node-Red, and simularities with the Notes Database. Like documents, views and even replication.

Not that weird as you start looking closer, Cloudant is the cloud version of CouchDb. Which is invented by Damien Katz, who also was involved by the creation of the NSF.

I found on the internet a very nice easy to use open source project, Java-cloudant, who is doing the heavy lifting in the interaction with Cloudant.

The plugin

I have added in the plugin the most basic interactions with the Cloudant, like CRUD for a single document, CRUD bulk for documents and some databases interaction.

Everything starts with the creation of a CloudantConnector instance, which needs the account, username and password to setup the connection

CloudantConnector connector = new CloudantConnector(account, username, password);

The database interactions, currently in the plugin

List dbs = (List) connector.findAllDatabases();
connector.setDatabase(String dbName, boolean create);
connector.createDb(String dbName);
connector.deleteDb(String dbName);

To interact with documents,there is a need to set a specific database. Where the create parameter is a boolean. If true, the database will be created if not existing.

connector.setDatabase(String dbName, boolean create);

The CRUD interactions for a single Document and bulk documents.

connector.createBulk(List objects);
connector.updateBulk(List objects);
connector.deleteBulk(List objects);
List list = connector.findAllDocuments(Object.class);
List list = connector.findAllDocumentIds();

connector.save(final Object obj);
connector.delete(final Object obj);
connector.update(final Object obj);
Object obj = connector.find(Class cls, String id);

 

An example

Below I get all my notifications from a cloudant database on BlueMix

blue mix-cloudant-xpages

 

Where is the code

I have open sourced the code in GIT repository on Bitbucket. Inside is the plugin, but also the update site which can be imported in an Update Site Database on a Domino Server. For more information see the ReadMe in the repository.

 

Contribute

If there is a need for other methods, let me know in the repository issues section, or better contribute to the project by making a fork of the repository and afterwards make a pull request.

 

Happy coding….

twittergoogle_plusredditpinterestlinkedintumblrby feather

Hello Jackson4XPages f.k.a Jackson JSON wrapper

moving-git-preview-opt

Last week I was thinking about the future of my Jackson JSON wrapper after I added new features, mostly because I needed them for my XPages pet project. Paul Withers was suggesting to contribute it to OpenNTF as project new style.

At Engage I spoke with Christian about the steps to be taken, so I proposed my idea at the OpenNTF new_idea channel on Slack.

Now there is a Stash repository and Jira project. I have moved all my code to this new repository and refactored the code to meet the package names of org.openntf…..

So let me know if you want to contribute code,there are so many awesome stuff inside the Jackson packages which could be helpful.

twittergoogle_plusredditpinterestlinkedintumblrby feather

Quick XPages tip: add pace.js to your app

pace-js-custom-loading-bar-featured-720x340

Last week John Jardin pointed me to a very interested progress bar project, Pace JS.

It is a loading progress bar which runs out of the box only by adding the Javascript and CSS theme. There is a possibility to configure it, but it is not necessary.

Getting started

I added in bower.json file the Bower package name and run Bower to update my client side framework in my On Disk Project.
{
“name”: “bower4xpages”,
“version”: “0.0.1”,
“dependencies”: {
“bootstrap.growl”: “latest”,
“eonasdan-bootstrap-datetimepicker”: “latest”,
“moment”: “latest”,
“underscore”: “latest”,
“fontawesome”: “latest”,
“pace”:”latest”
},
“private”: true
}

Next step is to refresh my On Disk Project in the Navigator inside the Domino Designer and sync the Database with my On Disk Project.

Include it

In my theme I only have to add 2 new entries

<resource>
		<content-type>application/x-javascript</content-type>
		<href>libs/pace/pace.js</href>
	</resource>
	
	<resource>
		<content-type>text/css</content-type>
		<href>libs/pace/themes/blue/pace-theme-minimal.css</href>
	</resource>

Build my application an reload a page in my XPages app……… but there was an javascript.

There is a need to disable in the AMD loader in the javascript file, or use the working around at XSnippets.

To disable AMD in the Pace.js file, replace this

if (typeof define === 'function' && define.amd) {
    define(['pace'], function() {
      return Pace;
    });
  } else if (typeof exports === 'object') {
    module.exports = Pace;
  } else {
    if (options.startOnPageLoad) {
      Pace.start();
    }
  }

By this

if (options.startOnPageLoad) {
      Pace.start();
    }

Happy coding…

twittergoogle_plusredditpinterestlinkedintumblrby feather

Update of the Jackson JSON mapper plugin

jackson-java-json

Today I was busy writing a REST API for a XPages application. That was a good point to update my Jackson JSON mapper OSGi plugin,which is an wrapper around the powerful Jackson JSON project.

I have split 1 method in 2 and I have added 3 methods which accept a ObjectWriter as parameter.

New methods

write value from POJO object to JSON string, but nice formatted
JacksonWrapper wrapper = new JacksonWrapper();
String json = wrapper.writeWithDefaultPrettyPrinter(POJOObject(s));

write value from POJO object to an OutputStream

JacksonWrapper wrapper = new JacksonWrapper();
wrapper.writeValueToOutputstream(POJOObject(s));

write value from POJO object to an FileWriter

JacksonWrapper wrapper = new JacksonWrapper();
wrapper.writeValueToFilewriter(POJOObject(s));

write value from POJO object to an File

JacksonWrapper wrapper = new JacksonWrapper();
wrapper.writeValueToFile(POJOObject(s));

I have updated the GIT repository on BitBucket. It also includes the update site, with the latest plugin.

Happy coding..

twittergoogle_plusredditpinterestlinkedintumblrby feather

Nice workaround to JSF 1.x EL limitation

jsf

At a customer we have portals build with JSF 1.2, yeah I know ;-). Today is was interesting to found a solution for a problem.

In JSF 1.x there is a limitation of the Expression Language. It is not possible to pass parameters  in methods in EL to controller bean.

I found a nice workaround for this limitation by using the setPropertyActionListener
Below is a button where this ActionListner is used

<h:form>
    <h:commandLink value="Click here" action="#{myBean.action}">
        <f:setPropertyActionListener target="#{myBean.propertyName1}" value="propertyValue1" />
        <f:setPropertyActionListener target="#{myBean.propertyName2}" value="propertyValue2" />
    </h:commandLink>

    <h:commandButton value="Press here" action="#{myBean.action}">
        <f:setPropertyActionListener target="#{myBean.propertyName1}" value="propertyValue1" />
        <f:setPropertyActionListener target="#{myBean.propertyName2}" value="propertyValue2" />
    </h:commandButton>
</h:form>

And this connected to the managed bean.

public class MyBean {

private String propertyName1;
private String propertyName2;

public void action() {
System.out.println("propertyName1: " + propertyName1);
System.out.println("propertyName2: " + propertyName2);
}

public void setPropertyName1(String propertyName1) {
this.propertyName1 = propertyName1;
}

public void setPropertyName2(String propertyName2) {
this.propertyName2 = propertyName2;
}

}

Happy coding….

twittergoogle_plusredditpinterestlinkedintumblrby feather