XPages Bug when validating a datetime value

this is a real strange one and it took me quite a while to nuderstand what’s happening:

on an XPage I’m having an EditBox to collect Date values. Display type is “Date/Time”, Display format is “custom” with a German date pattern “dd.MM.yyyy”), and the “date/time picker pop-up” option is selected.

Now this field must be validated in a way that the user may not enter a date prior to the current week’s Monday. So in the Validation property / Validate Date/Time area I set the “Minimum” option to computed and entered the following code:


var tmpWD = @Weekday(@Today());

var earliestStartDate = @Today();

switch (tmpWD) {

case 1: //today is sunday

	earliestStartDate = @Adjust(@Today(), 0, 0, 1, 0, 0, 0);

	break;

case 2: //today is monday

	earliestStartDate = @Today();

	break;

default: //every other weekday

	earliestStartDate = @Adjust(@Today(), 0, 0, (2 - tmpWD), 0, 0, 0);

	break;

}

return earliestStartDate;


running the XPage and entereing a date that must be valid (this week’s monday i.e. July, 29 2009) I still receive a validation error.

If I go back into the designer, I now can see that the calculatuion for the “default” case soemhow has changed to

earliestStartDate = @Adjust(@Today(), 0, 0, (2 / tmpWD), 0, 0, 0);

so that now Division is performed instead of a Difference!!

Playing around for a while I observed that if I open the source editor and scroll down to the given code, and then call the code editor and entering the correct code (with 2 - tmpWd) and then close the code editor, the formula in the source editor immediately switches to the division again. Only if I change the code in the source editor itself and then save it, it remains to be a substraction.

Just to learn more about that, I temporarily entered a computed field and had it calculate its value through the same code. And here the arithmetical signs are NOT altered, so there must be a connection with the validation property.

I also tried this in various databases, but not in various Designer clients. So there is a chance that it’s my local client that’s gone berserk

Would someone please find the time and try this out for me? And possible write an SPR (as I can’t do it) in case it’s confirmed?

Thanks all

Subject: Reproduced.

I created SPR SODY7TKGQC

For a workaround you can do the following as it stops it converting.

var xx = 2 - tmpWd

earliestStartDate = @Adjust(@Today(), 0, 0, xx, 0, 0, 0);

also …

earliestStartDate = @Adjust(@Today(), 0, 0, 2 - tmpWd, 0, 0, 0);

Subject: sorry, still not working

Tried to change my code like that, but no luck:


	var diffDays = 2 - tmpWd;

	earliestStartDate = @Adjust(@Today(), 0, 0, diffDays, 0, 0, 0);

	break;

I still have to change the code directly inside the source editor. Doing so and then saving the page, everything’s fine. If then I double click the {Computed} link in the properties pane I still see the code as I changed it in the source editor. But upon closing the code dialog the “-” is set back to be a “/” in the source editor.

There’s one more (maybe important) info I forgot to mention in my original post: the date Edit box isn’t sitting in an XPage directly but it’s part of a Custom control. I just tried to create a similar edit box directly on an XPage, which shows exactly the same behaviour, though. But maybe it’s one more hint to you…

One other thing I observed just now is that the code altered in the source editor probably isn’t synced properly to whatever feeds the code dialog. Steps to reproduce:

  1. I start with my code correctly showing a “-” instead of a “/” in the source editor; the page is not modified since saved (no * in the title tab)

  2. hover the {Computed} link in the properties pane ==> the popup shows the correct code

  3. double-click on the {computed} link in the Properties pane to open the code editor ==> code is still correct, so I don’t change it, just click OK to close the dialog

  4. the “-” again is being replaced by a “/”, the page’s title tab says that the page has been modified (* showing) (BTW: obviously there’s no difference between closing the dialog with OK ar CANCEL; this always seems to trigger a “modified” flag for the underlying page, and it also changes my code)

  5. set focus to the source editor pane and hit CTRL-S to save the page ==> page obviously is saved now (* is gone)

  6. hover the {Computed} link in the properties pane again ==> the popup still shows the correct code, with a “-” instead of a “/” while the source editor shows the incorrect version

  7. double-click on the {computed} link in the Properties pane to open the code dialog again ==> also here the code is still correct, showing a difference to the one in the source editor

Can you reproduce as well, or could it be that this is due to a corrupt eclipse workspace file set?

Subject: Thanks for the clarification.

I have updated your SPR with the latest details. Once I followed them I could reproduce as well.