OK, here we go again. It seems that the onClick event of a link is again firing at page load. Here's what I'm attempting to do. I've got a link with an onClick event that builds a dojo._Calendar widget and displays it on the page. When a date is selected we hide the widget and set a sessionScope variable. The widget has an event defined for onValueSelected that runs when a date is selected within the widget. Now, we're wanting to change a sessionScope variable when a new date is selected within the widget and then reload the page so that the new date is used to build the month/day/week calendars talked about in the SnTT series on building a functional XPages calendar. Now I think this is running at page load time because:
- The sessionScope.dispDate variable is changing to December 1, 0001 on page load instead of retaining today's date.
- The date at the top of the page which resides over the field is keeping the proper sessionScope variable value.
- Everything below the field is built using the date value from the field.
I believe the December 1, 0001 date is being set because I'm using the value returned from a selection made within the dojo._Calendar widget. At page load there is no value being returned, so it's just picking the December 1, 0001 date for whatever reason. Now, last time I complained of onClick/PageLoad weirdness, it turns out it was my own fault, which I suspect may be the case here, but I find it odd that I encounter all this weirdness within link\onClick events.
So, to ensure I'm not crazy I'm posting the code below. The part of this that making me think this is running at page load is the onValueSelected part. I'm thinking maybe I can just put code here but for some reason it seems I read that it's expecting a reference to a function, which may be causing this behavior:
This is the link's onClick event:
This is the function setSessScope() which is used only for setting sessionScope variables from client side JavaScript. This function is contained within a Server Side JavaScript library. Of note here, the context.reloadPage() call doesn't work when the function is called via the onClick event, but seems to work when called during Page Load:
Now, I understand that this whole exercise is really an exercise in futility as surely IBM will release calendar support in XPages at some point in time, but I've learned a lot from members of the community about XPages and just building this entire app as a whole. It incorporates using Client Side JavaScript to manipulate the DOM and interacting with Server Side JavaScript. It uses Dojo pretty extensively, scoped variables, property definitions, plus a whole array of other techniques which I've scraped from various parts of the Yellow Verse. And maybe, just maybe been helpful to other folks who need a calendar of some type right now, at least I hope it's been helpful.
So that's it. Hopefully someone will enlighten me on the intricacies of the onClick event and reassure me it's my fault and not the product's.