Probably the best thing about being the XPages test lead for IBM Domino 8.5x is that you get to play, sorry I mean work with the thing all day. Seeing all the cool stuff that can be done with XPages is also great and you don't have to be a super-duper developer (or a developer for that matter) to get going. If it didn't take you long to design databases on Lotus Notes, then it's not a big step to XPages.
Part of my role as test lead is to monitor the forums and blogs. Pick up on how people are using XPages and if they hit problems, get them addressed. These problems usually fall into two categories, Bugs and How-to's. The validated bugs get put into the system and the team here resolves them. The How-to's a more fun. Here you get to chance to try ways, push the technology and find solutions.
One of the first How-to's which I worked on after the release Lotus Notes Domino 8.5 was in a nutshell to do with performing validation and no validation all on the same XPage. The scenarios was this. You have an editbox that has Ajax type-ahead going on for a person's name - with the suggestions populated by a @DbColumn lookup. If the desired name exists in the list, upon leaving the editbox a @DbLookup is performed using the person's name as a key which gets the details of that record and populates other fields further down in the XPage. And if the name doesn't exist or you have a new name, the person's detail fields need to be filled-in (or filled-out) manually. And of course, some of these details are required and some are not (see snippet).
Company = @DbLookup(@DbName(), "vwProfiles", nm, 2);
Email = @DbLookup(@DbName(), "vwProfiles", nm, 10);
if(nm == null){
getComponent("Company1").setValue("");
getComponent("Email1").setValue("");
}else{
getComponent("Company1").setValue(Company);
getComponent("Email1").setValue(Email);
}
}]]>
refreshMode="complete" immediate="false" save="true">
This is where the fun starts.
When we run this, it fails on the onblur event as validation kicks in before the details from the lookup can be set to the Company and Email fields.
So, lets try setting no data validation on the onblur event. That should take care of things, right? Wrong. This acts like a cancel action and thus stopping the setting of the Company and Email details. Back to square one.
There's got to be a way, and there usually is with XPages. The answer lies in knowing a tiny bit about the JSF lifecycle. Just a tiny bit now - don't think you got to start reading books upon books about it, and thankfully my colleague Maire Kehoe has written an article titled "The Events "No data validation" option in XPages" in the Designer Wiki
What we are going to have to do in our example is catch the values before they hit validation. And to do this we are going to use 'getSubmittedValue()' instead of 'getValue()' for the lookup, and then use 'setSubmittedValue()' instead of 'setValue()' to add the details to the Company and Email fields.
var nm = @DbLookup(@DbName(), "vwProfiles", getComponent("FullName1").getSubmittedValue(), "FullName");
Company = @DbLookup(@DbName(), "vwProfiles", nm, 2);
Email = @DbLookup(@DbName(), "vwProfiles", nm, 10);
if(nm == null){
getComponent("Company1").setSubmittedValue("");
getComponent("Email1").setSubmittedValue("");
}else{
getComponent("Company1").setSubmittedValue(Company);
getComponent("Email1").setSubmittedValue(Email);
}
Now the onblur event can do it's job, and validation also happens when the required fields haven't been filled in.
Hope this helps? Now back to work... sorry I mean play with XPages.
p.