While working on an Xpages Workflow Engine of one of our customers, I came across a requirement to do backend field validations in SSJS. As the field validation is done via the workflow engine, we were not able to use standard validators. The engine was able to do this already and would eventually spit out validation errors based using addFacesMessage() and a default Error Messages Control.

The fields to check for are defined in the workflow step definitions. In there, I added not only the field names to check but also to corresponding ids from the XPage controls to that definitions. Now, the workflow engine does the validation on fields and attributes and returns a list of ids that are invalid that are stored in a session scope variable for the sake of simplicity. We will be moving this to a bean sometime in the future. To highlight the fields now, I use an additional attribute in the xpages controls that I call "highlighted":

Image:SSJS Field Validation and highlighting of fields without standard validators

This computes a value of "1" if it's part of the invalid ids list and "0" if not. Like this:

try  {

var me:javax,faces.component.UIComponent = this;
var myID:String = me.getId();

var invalidFields:String = myBean.getInvalidFieldListAsString();
if(invalidFields) {

if(@Contains(invalidFields,myID) {
return "1";
} else {
return "0";
} else {
return "0";
} catch (e) {
return "0";

To actually highlight the fields, I dynamically change some CSS style values in the onLoad Event by selecting all the nodes with an attribute value of highlighted="1" using dojo.query() like this:

nodeList = dojo.query("[highlighted]");
nodeList.forEach(function(node) {
  try {
    var value = node.attributes["highlighted"].value
    if (value=="1") {
            dojo.setStyle(node, "background", "lightyellow");
            dojo.setStyle(node, "border", "2px solid red");
  } catch (error){

I then set background color and border color respectively. The cool thing about this is that I can also highlight a group of fields by putting them in a separate panel an adding the "highlighted" attribute there as well. I only need to hook up the field to validate with the id of a specific panel. the result looks like this:

Image:SSJS Field Validation and highlighting of fields without standard validators
Heiko Voigt   |   24 July 2014 16:23:26   |    XPages  SSJS    |  
  |   Next Document   |   Previous Document

Discussion for this entry is now closed.

Comments (0)

No Comments Found