Wednesday, January 20, 2016

Looking Forward to IBM Connect 2016

In less than two weeks I am excited to attend IBM Connect 2016 in Orlando. It is now a full twenty years that I have worked in the yellow bubble.  I was just a newbie when I attended my first Lotusphere in 1996. I went again in 1999, and then not again for another fifthteen years until 2014. This will be my fourth time.

As is always the case, there are many great sessions this year. The sessions are only part of what makes the conference great, the other part is the people you meet.

These are my top 5 sessions that I am most looking forward to attending.


1) Real-Time Video Chat XPage Application Using Websockets and WebRTC Technologies:  This seems like a fascinating session and I am excited to hear from Csaba Kiss who I met at MWLUG this past August.

2) Optimus XPages: An Explosion of Techniques and Best Practices: I am excited to see my friend John Jardin again. He is a dynamic speaker with a passion to share knowledge.

3) The Grid, the Brad, and the Ugly: Using Grids to Improve Your Applications:  Brad Balassaitis's blog has been a huge help to nearly every XPages developer. It will be great to hear his latest take on the grid choices that we have now.

4) 'Marty, You're Just Not Thinking Fourth Dimensionally': Troubleshooting XPages: Paul Withers is a brilliant developer and I am really looking forward to his session.

5) Outside the Box: Integrating with Non-Domino Apps Using XPages and Java: This is an area where I have quite a bit of recent experience. It will be great to hear what Julian Robichaux and Kathy Brown have to say on the subject.

There are many other sessions I am looking forward to as well.  If you are still considering whether to attend the conference this year it is not too late. The nice thing this year about being off Disney property is that there are several nearby hotels within walking distance that have very reasonable prices.  

Thank You, Thank You, Thank You


I also have unfinished business in thanking those who nominated me for IBM Champion. It is a great honor to have been chosen this year. I want to specifically thank Mark Roden who told me 2 years ago that I could be a champion. I didn't know what to think at the time, but that confidence did motivate and encourage me,


Tuesday, November 17, 2015

Limiting Keyboard Input in XPages

One way to make your validation easier is limit the types of characters allowed in a specific input field. For example, if you have a numeric field you simply don’t allow the user to type a letter in that field. If you know that an email address cannot contain special characters, you can simply prevent the user from typing those special characters. I would caution that if using this technique for public facing applications, that the use of tooltips or helper text be considered.

Last Thursday I was told that in my application, the field was allowing the entry of numbers from the main keyboard but not the numeric keypad. I discovered that the behavior of the dojo combobox differs from that of the core controls. In this post, I will explain the usage of the keypress event in general, and then explain how to use it with a dojo combobox. 

Before I begin, I have to laugh at the irony of this new Stack Overflow question (http://stackoverflow.com/questions/33680515/how-to-prevent-special-characters-input-into-edit-box) about this very subject that appeared a few hours after working on this. Amazingly no one had answered it by the time I saw it, and of course it was fresh on my mind, so I answered it with what I was already going to put in this new blog post.

Keyboard Events


There are three key events that you can use. The onkeypress, and the okeydown, and the onkeyup. As the name implies these are keyboard events. In XPages you can assign client and/or server code to each. I would strongly caution for performance reasons against doing anything serverside that is more complicated then setting a scoped variable. The code that we want to use to limit certain keys is all clientside javascript.

Usage in an Edit Control



This code shown here will only allow numbers and the backspace key. In XPages, if applied to a core control, this also allows the numeric keyboard to work even though it uses different keycodes. The
keycodes for the numeric keyboard are 96-105. For an edit box the only event you need is the onKeyPress.

Usage in a Dojo Combobox


One of the nice features of the dojo combobox is that you can choose from the list or type in a value. You also get built in type ahead. The key events work differently in two specific ways though. If you just use the onkeypress event, then if the user types really fast they can bypass the event and type an unwanted character. These are the types of things the quality assurance people are happy to point out to you. The way to prevent this behavior is to put the code in both the onkeydown and onkeyup events.


How to selectively include or exclude any key


My example above on specifically includes numbers, your needs may differ. You can use http://keycode.info/ to easily figure out any keycode. Modify the code below to meet your specific requirements. This example only allows letters, numbers, backspace, and delete.

var keyCode = event.keyCode;
if((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90)|| keyCode == 8 || keyCode == 46){
   event.returnValue = true;
}else{
   event.returnValue = false;
}

Thursday, October 1, 2015

Creating JSON objects in Java using the JSON.simple toolkit

I needed a way to create JSON objects in Java for displaying in a grid. There are several options for doing this that I could have chosen. There is GSON from Google, or I could roll my own using StringBuilder. After doing some research, I decided to use the JSON.simple toolkit because, the examples looked simple and straightforward to me.  In this post, I will explain how I used JSON.simple and give two real life examples.


Installation

To use JSON.simple you need to download the jar and add to your build path. The jar is available here: https://code.google.com/p/json-simple/


Creating a Single Object


In this snippet, contents of a NotesDocument are added to a JSON object and then that object is passed back to the caller of the method. Note this example uses the Name class from the original Notes,jar to format the Notes name. It is the java version of @Name.

Document doc = col.getFirstDocument();
JSONObject json = new JSONObject();

if(doc != null){
   Name name = session.createName(doc.getItemValueString("EmployeeName"));
   json.put("employeeName", name.getCommon());
   json.put("employeeID", doc.getItemValueString("EmployeeID"));
   json.put("employeeLocation", doc.getItemValueString("locationdesc"));
   json.put("employeeRole", getEmployeeRole(name.getCommon()));
}
returnValue = json.toJSONString();
...
return returnValue;

The result will look something like this:

{"employeeLocation":"Pensacola Milton","employeeRole":"Intern to the Intern","employeeID":"12345","employeeName":"Dwain Wuerfel"}


Creating a Collection of Objects


In this snippet, the contents of a multi-value document are traversed and a JSON object is created for each item. Many will recognize that I am grabbing the members of a Name & Address Book group. For each member I create a new object and then that object is added to a JSONArray object called ‘result’ which is then returned to the calling method. Each object will be a displayed on a separate row in the grid.

JSONArray result = new JSONArray();

if(nabDoc != null){
   Item item = nabDoc.getFirstItem("Members");
   Vector<String> v = item.getValues();

   for(String person : v){
   Name name = session.createName(person);

   JSONObject json = new JSONObject();
   json.put("employeeName", name.getCommon());
   json.put("employeeRole", employeeRole);
   json.put("employeeID", EmployeeID);
   json.put("employeeLocation", EmployeeLocation);
   result.add(json);
}
returnValue = result.toJSONString();
...
return returnValue;

The result will look like this if there are three JSON objects in the array:

 [{"employeeLocation":"Pensacola Milton","employeeRole":["Minion"],"employeeID":"12345","employeeName":"Dwain Wuerfel"}, {"employeeLocation":"Pensacola Milton","employeeRole":["Blog Author"],"employeeID":"91984","employeeName":"Steve Zavocki"},{"employeeLocation":"Pensacola Milton","employeeRole":["Cast Member"],"employeeID":"54321","employeeName":"Vernon Miles"}] 

Conclusion


As the name implies the JSON.simple toolkit is simple to use, and a good option to consider if you need to create JSON objects within your java code. In case you are interested in learning more about your other options, here is an article that compares three different json toolkits including JSON.simple.