In my current project I was tidying up validation message controls and decided to us Ye Olde facesContext to help me out.
The issue is that in this application every single custom control that displays data is dynamically bound to its data source. In addition, there are editing, print-to-pdf, print-base, print-final and, at last, print-to-diff versions of each of these controls.
Well…the only time I really need to display the error controls was in the editing-versions of these controls but the UI complication is that sometimes, not always, these controls are in table cells or otherwise surrounded by other dynamically generated content whenever they are included on an XPage.
Bottom line: I wanted to add two returns after each Display Error control but ONLY if there was an actual error. Otherwise I would have two extra returns on screen multiplied by n number of times in a repeat control.
In my typical brute force fashion, I remembered this XSnippet and created a custom control that contains two returns that display when only there is a server-side validation error.
I drop this control right next to the Display Error controls where I need it and it works like a champ.
If there is a server-side validation error, I get the error message plus a couple of extra returns below it which really improves the UI by adding more white space.
Don’t know if that is the best way to do it but it works. Custom Control code is below.
you can also do a render when on a
You can also use CSS and set padding-bottom for class .xspMessage
That's a good idea. If I had consistent messages and placement I would do it that way for sure.
Funny, I did this very thing yesterday after reading your xsnippet.
In my case I had a form with heaps of fields and didn't want to have an xp:messages control with 30 errors in it – I just wanted a generic "Validation failed" message at the bottom telling them to review the form and look for the error flags.
Nice one!
Excellent! Thanks! Nice usage.