359 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
Design changes during SmartCloud Notes migration
Mon, Feb 24th 2014 143
Processing multiple users in the SmartCloud Notes administration UI
Fri, Feb 14th 2014 207
The property role is deprecated and no longer supported.
Fri, Nov 1st 2013 159
OpenSocial and Domino - seeking feedback
Tue, Oct 29th 2013 145
I’m on TV for several seconds...
Mon, Jun 24th 2013 140
Followup on getting long-standing bugs fixed
Wed, Jun 19th 2013 106
XPages best practice: computed selection lists
Fri, May 24th 2013 137
Top 10
Better SSJS validation for XPages
Wed, Jan 5th 2011 211
Processing multiple users in the SmartCloud Notes administration UI
Fri, Feb 14th 2014 207
The property role is deprecated and no longer supported.
Fri, Nov 1st 2013 159
Searching for blank date fields, and what makes a supported feature
Mon, Oct 31st 2011 157
OpenSocial and Domino - seeking feedback
Tue, Oct 29th 2013 145
Design changes during SmartCloud Notes migration
Mon, Feb 24th 2014 143
I’m on TV for several seconds...
Mon, Jun 24th 2013 140
Beware <script> in XPages
Wed, May 15th 2013 139
XPages best practice: computed selection lists
Fri, May 24th 2013 137
Delete empty folders, take 2
Wed, Apr 10th 2013 129


Better SSJS validation for XPages
Andre Guirard    

I've been doing some XPages development recently, and I was frustrated by some inconvenience in doing server-side validation using JavaScript.

The typical way of doing a series of validations on the same field, is to have a message and condition for each test, e.g.:

<xp:inputText id="inputText1">
     
<xp:this.validators>
             
<xp:validateRequired
                     
message="This here is a required field.">
             
</xp:validateRequired>
             
<xp:validateExpression
                     
message="The item must be at least 3 characters">
                     
<xp:this.expression><![CDATA[#{javascript:(value.trim().length >= 3)}]]></xp:this.expression>
             
</xp:validateExpression>
             
<xp:validateExpression
                     
message="RTC must be followed by four digits.">
                     
<xp:this.expression>
                     
var valu:string = value.trim();
                      var exp = new RegExp("^rtc[0-9]{4}$", "i");

                      return (!valu.startsWithIgnoreCase("rtc")

                              || valu.match(exp)

                       );
}]]></xp:this.expression>
             
</xp:validateExpression>
     
</xp:this.validators>
...

If the validation might result in multiple mesages, you have to split it up according to which message you want to display, and often end up repeating some work with each condition (such as trimming the string in this case, or testing some other fields to see whether there are some restrictions on this one). You can't put all the validation code into one tidy little subroutine in a server JavaScript library.

Of course, you could have one piece of code that returns true or false and also assigns a viewScope variable that would be read by a computed message element, but that's a little kludgy.
I found the
customValidator element, and the linked article is nice if you want to do validations in Java. But I preferred to add the code to an existing JavaScript library. Fortunately for me, I have access to the people who designed this stuff, so I asked them how to do it and they told me about a couple of system functions I never found in my searching! So, you can start with the following code which includes those calls:

function postValidationError(control, msg) {
     
// msg is the error message string; control is the component being validated
     
// ('this' from the caller).
     
if ((typeof msg) != "string")
             
return;
     
var msgObj = new javax.faces.application.FacesMessage(
              javax.faces.application.FacesMessage.SEVERITY_ERROR, msg, msg

      );

     
facesContext.addMessage(control.getClientId(facesContext), msgObj);
      control.setValid(
false);
}

Put that in your JavaScript library, then write multiple tests in a single piece of JavaScript code, such as:

...<xp:this.validators><xp:customValidator>
     
<xp:this.validate><![CDATA[#{javascript:
var val = value.trim();

if (val.length < 3)

      postValidationError(this,
"The item must be at least 3 characters");
else if (valu.startsWithIgnoreCase("rtc")) {

      var exp = new RegExp("^rtc[0-9]{4}$", "i");

      if (!val.match(exp)) {

              postValidationError(this,
"RTC must be followed by four digits.");
      }

}

}]]>
</xp:this.validate></xp:customValidator>...

To make things a little simpler, the postValidationError checks the datatype of the msg argument, so you can write a validation function that returns null when valid (or true or any non-string), or the message if not valid. Then you can call postValidationError unconditionally with this return value, and it'll do something appropriate. Note that for a custom validator, the return value is ignored; if you don't do anything to flag the control as invalid, it's assumed to be valid.


---------------------
http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/better-ssjs-validation-for-xpages
Jan 04, 2011
212 hits



Recent Blog Posts
143


Design changes during SmartCloud Notes migration
Mon, Feb 24th 2014 11:00a   Andre Guirard
We've been having a problem with one customer who was migrating their on-premises mail users into SmartCloud Notes, because they ade a mail template change in their on-premises environment after giving us "staging" replicas of some users' mail files. The DESIGN task on the users' on-premises servers updated their mail file designs from the template, and this change replicated to users' local replicas (MMRs in this case). When the users replicated their local mail files with the service, th [read] Keywords: ldd lotus notes server
207


Processing multiple users in the SmartCloud Notes administration UI
Fri, Feb 14th 2014 9:00a   Andre Guirard
I thought I should note this change, since there's nothing in the "liveAdmin" UI (as yet) to indicate how it works. That will have to wait until we can translate the explanatory text into all our supported languages. But you can use the new functionality now. If you have a set of SmartCloud Notes users that you want to -- let's say -- assign a new mail file design using the web-based administration UI, you used to have to search for the user, select them from the search results, click the bu [read] Keywords: administration ldd lotus notes
159


The property role is deprecated and no longer supported.
Fri, Nov 1st 2013 7:13a   Andre Guirard
I recently started using the Domino Designer 9.0.1 client, and immediately noticed this slightly alarming warning in my XPages applications. The product help page "What's new in IBM Domino Designer 9.0.1 Social Edition?" lists several XML elements for which a "role" property is deprecated (search for "Obsoleting of the role property") but it was unclear whether it would still work anyway and how any difference in the build version versus the execution version was a factor. Role is used to [read] Keywords: domino ibm ldd lotus xpages application applications server xml
145


OpenSocial and Domino - seeking feedback
Tue, Oct 29th 2013 12:50p   Andre Guirard
If you've been doing development work that involves OpenSocial and Domino, I'm interested in quizzing you a little. Please reply privately using my email, which is my first and last name, with underscore, @us.ibm.com. Thanks. [read] Keywords: domino ibm ldd lotus development email
140


I’m on TV for several seconds...
Mon, Jun 24th 2013 10:00a   Andre Guirard
At about 1:10 in this news clip: http://minnesota.cbslocal.com/2013/06/23/at-the-fix-it-clinic-learn-to-fix-your-electronics-appliances/ Fixin' stuff. As I do. [read] Keywords: ldd lotus
106


Followup on getting long-standing bugs fixed
Wed, Jun 19th 2013 3:53p   Andre Guirard
A little while ago I wrote about our process for prioritizing bugs for fixing. Mathieu Pape has a related idea recently posted on IdeaJam, that you might consider supporting if you're interested in this issue. It seems like a good notion to me. [read] Keywords: ldd lotus ideajam ideajam.net




137


XPages best practice: computed selection lists
Fri, May 24th 2013 12:50p   Andre Guirard
The low-down: XPages lets you write code to calculate the values for selection lists. The value your code returns may either be an array of strings, using the pipe symbol ("|") as a delimiter between display value and stored value, or it may be an array of javax.faces.model.SelectItem objects, which each contain a display and stored value as separate data items. It's your choice. The latter method, however, is more bulletproof since you don't have to worry about pipe symbols in your data. [read] Keywords: domino ldd lotus xpages application best practice development javascript properties
139


Beware <script> in XPages
Wed, May 15th 2013 12:30p   Andre Guirard
I may be stating the obvious, but I wasn't the only one on my team caught out by this, so I thought I'd best mention it. I recently discovered the hard way that there's a problem with using elements in XPages. Always use instead. Why, you ask? Either seems to work fine! The problem comes up if your application is translated. The code that decides what parts of your page are translatable doesn't know anything about the element, so your JavaScript code is marked as a localizable string. It [read] Keywords: ldd lotus xpages application best practice javascript
113


Working the system to get bugs fixed
Mon, May 13th 2013 9:20a   Andre Guirard
An issue recently came to my attention that (based on my informal poll) has been a thorn in the side for Domino administrators for quite a while. I've been trying to figure out how it is that it's never been fixed. I'm referring to the fact that end users, when they create or rename a folder, are allowed to use various characters that have special meanings in design element names -- backslash, vertical bar, underscore, forward slash (which causes problems in mobile) and enclosing the name in [read] Keywords: domino ibm ldd lotus notes notes client notesdomino bug development ideajam mobile
129


Delete empty folders, take 2
Wed, Apr 10th 2013 9:50a   Andre Guirard
I while back I wrote a post containing code to clean up empty folders from user mail files. Yesterday, someone pointed out to me that it doesn't take into account the fact that folders that contain subfolders can be technically empty, in the sense of containing no documents, but we don't want to delete them if they have subfolders which are non-empty -- or if they have subfolders we don't also want to delete. So I came up with a new version of the code that deals with those situations. As bac [read] Keywords: ldd lotus lotusscript application




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - Mobile Edition