Hosted By

Contact Me

Misc Links

OpenNTF BlogSphere LotusGeek CoComment Custom Button

Ads by Google

Welcome to keithstric.com!

I hope you find this site useful in some way or another. I strive to bring you all sorts of geeky information and solutions to your most frustrating of issues with the occasional rant on whatever topic, technical reviews and weblog. You'll also find many products that I've developed and make available for you to use however you like. So, grab a cup of coffee, sit down and visit for a while.

SnTT: Sectioned XPages Menu

06/29/2010 10:40 AM By Keith Strickland
>I recently completed my first "Production" XPages application. Messing with the XPages calendar really helped but I learned that too long away from something after just learning it is bad. But anyways, while researching for said application I came across the IBM Lotus User Interface Developer Documentation site. I don't know where or how I found it but it contains a wealth of information on the oneUI classes with examples using them. On this site I found a Menu with Sections and the app needed a sectioned navigational menu. Since I was using the XPages Framework for this application (BTW, this is a great package and makes it VERY easy to come up with a very nice looking, functional app very quickly) I decided to just make a few modifications to add the required navigational menu. I sent these changes over to Steve Castledine for inclusion in the XPages Framework. Whether or not he'll use it, I don't know, but hopefully he will.

To make this I created a new custom control and called it ccSectionSideMenu. This very closely resembles the ccSideMenu custom control within the XPages Framework.

Now, to support the computed field in the code above, I had to make some changes to the xpUtil Server Javascript script libaray. These are the 2 functions I added:


And I modified the createFromProperties function and just added this code in between Side Bar and Footer Column blocks:

I really can't take a lot of credit for all the Javascript code I listed above. This code was just adapted from other functions and code blocks already in that script library. So I guess Steve Castledine and/or Niklas Heidloff wrote this code and really deserve the credit as all I did was re-task it to meet my needs. But the last piece of this puzzle is the layout.properties file. I added the following:

#Side Bar Menu Sections
sideBarSectionMenu.title=Section1,Section2
sideBarSectionMenu.link=Section1.xsp,Section2.xsp
sideBarSectionMenu1.title=subMenu1.1,subMenu1.2,subMenu1.3
sideBarSectionMenu1.link=subMenu1-1.xsp,subMenu1-2.xsp,subMenu1-3.xsp
sideBarSectionMenu2.title=subMenu2.1,subMenu2.2,subMenu2.3
sideBarSectionMenu2.link=subMenu2-1.xsp,subMenu2-2.xsp,subMenu2-3.xsp

This just sets up the data to be parsed and turned into the sectioned menu and follows the same format as the footer columns section.

Here's what you end up with:
sectionedMenu.jpg

And that's it, hopefully you'll get some mileage out of this. I didn't have time to give it twisty support where the menus collapse when you close the section, but I do plan on adding that in the future when time permits or the absolute need arises. But as long as you don't have a ton of menu items to display this actually works really well. Enjoy!


Here we go again....

03/30/2010 12:06 PM By Keith Strickland

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:

  1. The sessionScope.dispDate variable is changing to December 1, 0001 on page load instead of retaining today's date.
  2. The date at the top of the page which resides over the field is keeping the proper sessionScope variable value.
  3. 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.


SnTT: XPages Calendar Control (Part 5), adding data to the day view...

03/18/2010 5:06 PM By Keith Strickland

If you recall we left off from Part 4 with a blank day and week view. Well, through much gritting and knashing of teeth I've finally got some data on the day view. Now before I go any farther, I would like to thank a few people whom without I'm sure I would still be sitting here scratching my head trying to figure out how to do this:

  • Nathan Freeman for pointing me to an Article by Jeremy Hodge on embedding data within an XPage in order to make it accessible via client side JavaScript
  • Jeremy Hodge for this article and also cluing me in on using the dojo.addOnLoad function
  • Steve Castledine for showing me that @DbLookup, sessionScope.get("whatever") works with client side javascript that is on an XPage
  • Julian Buss for this wiki article

In order to set some guidelines of what we're trying to accomplish:

  • Build a day view calendar with the times down the left side of the page and entry data for a specific day on the right
  • Entries should show duration like the Notes Mail Calendar using a rectangle
  • Entry rectangles should be as wide as the calendar unless there is more than 1 entry for an hour, then they should be side by side but still take up the entire width of the calendar

So, let's get started. First we need to define a few dojo resources. So, in the properties for the custom control navigate to the All Properties tab and add 4 resources:

  • dojox.gfx
  • dojox.gfx.move
  • dojox.gfx.shape
  • dojo.Colors
It should end up looking like this:
calendar-ccCalDayResources.jpg

We just need to get some data now and then we can start working on the function that will build all our entries. Go take a look at a post by Jeremy Hodge and then scroll down the comments where he replies to me and explains how to build a heirachial XML type data structure from the entries. Well, this is the precise method I used. I added a repeat control and then added my "tags" within this repeat with their values. I added a view to the data sources of the ccCalDay control and also defined a "keys" and set "exact match" to true so that the view would only contain the entries for this day:


Here's the source for the repeat which builds all of our data:

I guess instead of defining a view as the data source, I should probably do this via a Property Definition, but I just needed to get this thing working as I've been getting frustrated with trying to figure out pixel counts and such.

So, that gives us our data for all the entries. Now it's just a matter of getting this data when the day.xsp XPage loads and doing something with it. In the source of the ccCalDay custom control at the bottom I've added the following javascript to run a javascript function after the page loads.

The addOnLoadFunc is a function in the XPCalendarClient javascript library which is added as a source to the ccCalDay custom control. This function is the work horse of the day view and is what builds all the minute divs, sets the styles and adds the rectangles to the page.

So, I'm just going to briefly explain each of the loops inside this function. I'm sure there is a better way than how I've done this but at the moment this is the best I've come up with. So to start with we've got to get all the data we produced in the repeat above. The data above is contained within a div with an id of "contextual", we get all the nodes within the contextual div.

Next up we just get a couple more variables and get into our first loop. With this loop we get everything we need, start date/time, end date/time, duration, subject, tool tip, start hour, end hour, starting minutes, the hours the entry spans, the div id for this entry and lastly the number of divs that should be in the dayTimeMinutesContainer div. Now I know there is a problem here, because of something in this loop one of the limitations of this is that it only supports up to 2 different entries in any hour. I'm sure it's because of how I'm handling it so I just need to fix it. But here is the loop:

Next up we loop through all the entries we gathered above and build all the divs.

Ok, we now set the style of all the dayTimeMinutes-hour divs for each hour that only has one entry. I do this for single entry hours only, because it's easier to figure out where the dayTimeMinutes div will be placed on the page and how wide it will be if we only have to deal with containers which contain more than one dayTimeMinutes div. But in setting the style for the dayTimeMinutes divs we get the dayTimeMinutesContainer coordinates so we can determine exactly where on the page the dayTimeMinutes div will be placed. We have to determine it's location because it has a position of "absolute" and the dayTimeMinutesContainer has a position of relative. This allows us to place the dayTimeMinutes div anywhere on the page we want. But, we see how wide the dayTimeMinutesContainer is and also get it's X coordinates and pass that on to the style for the dayTimeMinutes div. While we're looping through all the entries we determine if a container has more than 1 div and if so, we just record that in another array.

Now we loop through the multiDivs array and set the style and determine the width of the dayTimeMinutes divs.

OK, the last loop will determine the Y coordinates of the div and then place a dojox.gfx surface on the page within the appropriate dayTimeMinutes div. This surface is what will hold the rectangle that represents the entry and duration. We also set a dojo color which in our case will be a gradient.

And that's it really. You should end up with something like this:
calendar-day-entries.jpg

UPDATE: I've added the demo application to the downloads section. Also, I forgot to mention, this works with all browsers except IE. I believe this may be a limitation with dojo.gfx, but more research will need to be done to determine this exactly.


More XPages onclick event weirdness...

03/11/2010 11:52 AM By Keith Strickland

I posted before about some weirdness with the onClick event code firing at page load time. I determined that if you edit the onclick event from the All Properties tab that you'll get this kind of behaviour. Well, here's another one.

The scenario, on the XPages Calendar, Day view I've got the normal navigation links at the top of the page to navigate forward/back a day. I'm using the dojo.gfx package to place day entries on the page (and making some decent headway by the way). On the day view page (ccCalDay) I've included a client side javascript library that contains the function which gathers data embedded on the page (Thanks Jeremy) and then places the dojo.gfx objects where they should go. Now, in the function which gets called for the dojo.addOnLoad event I get a node list of all the "calEntry" tags and their children using dojo.query. I then loop through each node and grab the "value" listed for that node. Simple enough, however the dojo.query call breaks the onclick of my navigation links.

Here's the code I placed in the Source of my ccCalDay custom control:


Now, for the function I just had:

Now, I know you're saying I must be doing something strange for this to be happening. Maybe I am, but I don't think I am, the code really isn't that complex. I set quite a few variables, build the gfx objects and that's it. I'm posting this because to me it's starting to show a pattern that the onclick event is flakey (that's a technical term by the way) at best. At worst it creates time consuming problems that don't make sense and are difficult to troubleshoot. While I know XPages are just starting to come into their own and are young but shouldn't these types of issues have already been found and addressed somewhere? Surely IBM and a lot of the business partners that get to see this stuff before it's released have run into some of these same types of issues? I say this because they build far more complex applications than myself that are tested and tested some more.

But here's how I got around this frustrating, time sucking issue. I went back to Julian Buss's XPages Wiki and this article to back track a little bit and put the addOnLoad back to how I originally had it and then added the calEntries call here instead of in the function. Here's what I ended up with in the Source of the ccCalDay custom control:


And the function now contains:


This seems to have corrected the problem but man what a headache. I'm not sure if this happened because of my inexperience with dojo and javascript or what. But I still think that the onclick event of links needs to be inspected a little bit more at IBM.


Dojo, XPages and Graphics, oh My....

03/04/2010 2:26 PM By Keith Strickland

OK, I've kind-of started working on placing entries on the day and week views of the XPages calendar. I've come across a feature of dojo called dojox.gfx. This is a vector graphics engine for placing shapes on the screen and is also used in the dojo charting side of things. Now, I'm not sure if this is the best thing to use but is what I've found so far that kind-of matches what I need to do. However, this library seems to be client side JavaScript driven, at least that's the only way I've found to get stuff to show up on the page.

With the gfx engine being client side JavaScript this poses a few problems:

  • I can't get at the sessionScope, viewScope and requestScope variables
  • I'm not sure how to get at the data I need unless we put it in a hidden field, which is of course doable
While these aren't really that big of a deal there are other hurdles to leap that may become a big deal.
  • You have to create a drawing surface to put shapes on and it is assigned a size, you then place a shape of a certain size onto the drawing surface. This is all controlled via x,y coordinates. While I could get the screen resolution of whatever browser is looking at the calendar, I would then have to accommodate all the different resolutions out there and figure out where to place a shape. This makes me shiver just thinking about it.
  • In CSS when you define a size in pixels, it's not really that size and the size you define also includes the padding and margins. So if you say something is 75px tall with a 1px padding. It's actually 77px tall, at least the best I can tell, it may be different depending on the monitor. This makes figuring out how tall to make an entry kind-of difficult. I guess I could loop through the time span making only small shapes that are all jammed together to make one big shape.

On the plus side, this is very cool stuff to be working with and it's very easy. I was putting shapes on the screen in less than 5 minutes and with only 4 lines of code to put a movable rectangle on the screen, development should be pretty quick, theoretically at least. The dojox.gfx engine also allows you to do gradients and path type drawings, rotate shapes via a slider, resize shapes and I'm sure some other stuff. Very cool.

So, that's where I'm at. If someone has a better idea on how to put entries on a day/week view calendar and then show their duration I'm all ears (or eyes as the case may be).


SnTT: XPages Calendar Control (Part 4), adding day and week views

03/01/2010 5:05 PM By Keith Strickland

In our last sessions we created a blank monthly calendar, then put some data on the calendar and last we made it reusable so we can use it in any application. While this is all well and good, we need to be able to see the breakdown of times on a daily and weekly basis. So in this SnTT we will be adding blank day and week views. I'm doing blank views because I can't quite figure out how to place entries so that they span the correct amount of time. If anyone has any ideas about this please speak up as I'm stumped as to where to go next. I was thinking that maybe Dojo could help out here but I haven't had the time to sit down and actually try anything yet. As of this release there is also an OpenNTF project for this of which I'm looking for people to contribute and be a part of the development of this project. Like I said before, I'm going to need people smarter than myself.

OK, so I started with making a couple of new XPages (day and week) and dragging the required XPages Framework elements onto the page, save and close. I then created a new custom control and called it ccCalDay. This control will have the following features/requirements

  • Navigate forward/back a day
  • Be able to configure the hours display (12 or 24)
  • At a later date, be able to add data to the view
  • Clicking the Month View sidebar link should take us to the selected month view
  • Clicking the Week View sidebar link should take us to the selected week view

We've now got our requirements so lets start putting this all together. I added a panel and called it "container". This panel holds the entire day view calendar. I added 2 other panels within the container panel and called those dayNavContainer and dayHoursContainer. Now that we've got our layout we can proceed. In order to display the proper day, we'll need some variables from the Month View calendar. I changed all the viewScope variables in the previous SnTTs to now be sessionScope variables instead of viewScope. This allows us to pass the date back and forth between different views. It also allows us to just manipulate one date at a time to change everything on a page. So, in the ccCalDay custom control, BeforePageLoad event we've got this:


If you recall, in our menu for each day on the monthly calendar we have a function which builds a list and we pass the day in a URL parameter. This is what allows us to define a specific day, we then just use the month and year from the "dispDate" sessionScope variable and then recompute all the other variables even though they aren't needed for the day view. I do this so if you go back to the month view we still have these values to build the monthly calendar, no matter how many days you navigate through on the day view. Also, I've built an array based on a property definition of all the times we want to display.

Now for the navigation, we want to be able to navigate forward or back by 1 day. This should be a fairly simple process but it did give me quite a bit of grief. Per Jeremy Hodge I tried setting the dispDate sessionScope varible like:
sessionScope.put("dispDate", sessionScope.get("dispDate").setDate(3));
but never could get this to work, along with several other methods I tried with using the set???? method of a Javascript Date, so that is one of the reasons why I had such a hard time with the navigation. I was also having some issues with the onClick event of the navigation links, the onClick code was firing at page load and incrementing/decrementing the sessionScope variables. I addressed that in this post. Just as an FYI, don't use the All Properties tab to edit event code, it screws things up. OK, now for the navigation we have a link that goes back 1 day, a computed field which displays the current date we're looking at and then another link to go forward 1 day. The back 1 day link has this onClick event code:


All this does is check the current day date, if it's 1, then we check if the month is 0 (Jan), if it is then we decrement the year by 1 and set the date to 12/31. If the month isn't 0 then we just decrement the month by 1. If the day isn't 1 we just decrement the day by 1. Once all of that is done, we set all the sessionScope variables.

For the date display, it's really simple:

For the day forward link, it's pretty much the same as the back link with the exception that we check if the day is the last day of the month and if it's the last month of the year.

The only thing left here is to build the table which contains all the different times. I defined a property definition for the timeHourFormat to be either 12 or 24. If you set it to 12, the times go from 12:00 AM to 11:59 PM. If you define 24 you get hours from 0 to 24. I also build a 4 row table within each data column which don't really contain anything right now. I'm hoping that by assigning these rows an id that we can place a div and have it span the proper amount of time. But this will probably change as I learn more about placing divs in specific spots on a page. So, at the top of the day view I display the date, week day, month and year, just like on the Notes Mail calendar day view. I use 3 separate computed fields so that we can place them where we want them and control their font sizes independently. The code for these are really straight foward and I'm not going to go into detail about these:

Big Date Number:


Big Week Day:


Big Month Year:


Then the remaining rows which are contained within a computed field which is contained within a repeat object:


All this does is loop through and build each row of the table based on the timeVar. timeVar is defined as the "collectionName" in the repeat control which is set to repeat 24 times. Then in each data column, build a 4 row table (for 0 min, 15 min, 30 min, 45 min).

And that's it for the day view of the calendar. You should end up with something looking like this:
dayView.jpg
Continue Reading for the week view....


Continue Reading...

Weird SSJS Time/Date stuff...

02/23/2010 3:30 PM By Keith Strickland

While working on the Day view of the XPages Calendar I've kind-of re-arranged the way I'm calculating the different parts of the calendar. Instead of using separate variables for the Month and Year I've setup a date variable which holds a JavaScript date object and then use the getMonth() and getFullYear() functions of the date object. This makes it easier to navigate between the different days and months, you just change that one variable and everything else gets computed from that one date. However, I've come across some weirdness (for lack of a better term) with the getMonth() function that I can't for the life of me figure out.

OK, so I've setup an array with the names of all the months. This is a zero based array because with JavaScript the month numbers are zero based. So, here's what I've got:
sessionScope.put("months", new Array("January","Feburary","March","April","May","June","July","August","September","October","November","December"));
sessionScope.put("dispDate",new Date());
sessionScope.put("dispCalMonth", sessionScope.get("dispDate").getMonth());

Now, the dispCalMonth sessionScope variable contains the correct month, which for Feburary is 1 (remember zero based months). Farther down the form I've got a computed field that uses:
var curMonth = sessionScope.months(sessionScope.get("dispDate").getMonth());
return curMonth;

Now, this is returning 0 (January) instead of 1 (Feburary). I can't figure out why and it's driving me nuts I've even returned just the number instead of the month name, and it does return 0.

Another issue I'm running into is using the setMonth(), setDate() and setFullYear() functions. These don't seem to work at all, at least not on sessionScope variables. I am able to set a new Date variable and use these functions and set the dispDate sessionScope variable to the new date variable. Which while workable, it is rather frustrating

These simple little things are the biggest hold up on Part 4 of the XPages Calendar which will include the day view and hopefully an "Alpha" release to OpenNTF. So, gentle reader, if you've got any ideas on what's going on here, please chime in while I still have a few hairs left.

UPDATE:
OK, in front of the computed field that displays the month is a link. In the onClick event of the link I decrement the dispDate sessionScope variable month. I removed this link and now the month display in the computed field is correct. So, it seems the onClick code is affecting the computed field somehow, so maybe someone can explain that one to me?

UPDATE #2:
OK, after searching the 8.5 Forum I found this post which said he got rid of all the event code and added it back via the source code editor. Well, I tried this with no joy. So, out of desparation I removed all the event code from the link and went and looked at the source. There was still an xp:this.onclick statement in the source and I still experienced the same results I defined above. This tag should not have been where it was, it should have been within the xp:EventHandler and then xp:this.action tags of the source. So I believe this is the whole problem. Now that I know what to look for it should be easy to spot. Also, I think the xp:this.onclick tag gets added if you edit the onclick event from the All properties tab instead of the events section.


SnTT: XPages Calendar Control (Part 3), making it reusable

02/09/2010 1:24 PM By Keith Strickland

In our previous posts we've created a blank calendar and then added some data to it. While this is all well and good, it's not very reusable in it's current state. It's quite dependent on a view being formatted a particular way. What if you already have a view with the data you want to put on the calendar and don't want to change that view? Well, this is what we're going to address today. With these changes the calendar really takes on the form of something useful and not something that only works on your machine.

In this SnTT I will show you how to make your calendar more reusable and we'll also add the framework for some navigation to each cell to open up a day view, week view and month view (the month view may be redundant and I haven't yet decided on if we need to keep it). Also being addressed here is if you want text other than what is in the calendar to show up in the dojo tool tip. As a bonus, we'll also do the blank view with an editable area so you can use your own custom control to display data.

So, with the requirements defined for this session, we're now ready to begin. Looking at the code for the dayCells computed field on the ccCalendar custom control, you'll notice our view name is hard coded along with the column values. This is where the problem lies, we want this to be configurable. We can use "Property Definitions" to address this issue. Property Definitions allow us to define our own properties for a custom control. These get stored in the "compositeData" object(?) and are available for you to use anywhere within that custom control.
Calendar-PropertyDefinition.jpg

Here we need to define some properties for the following:

  • The View Name - lookupViewName - String
  • The Data Column - lookupViewDataCol - Integer
  • The Column that contains the UNID - lookupViewUNIDCol - Integer
  • The Column that contains the Tool Tip text - lookupViewToolTipCol - Integer
  • The text that will used in the lookupViewToolTipCol if no Tool Tip text is available - NoTooltipText - String
You should end up with something like this:
Calendar-PropertiesDone.jpg

Now, open the default XPage, highlight the ccCalendar custom control (it'll be under facets) and fill in the properties we defined. Except here you can use values for your own view instead of the one included in this DB:
Calendar-PropertiesValues.jpg

Once you save and close and view the calendar in the browser, it should look exactly like it did when we left off from Part 2 of the SnTT. The only difference is that the tool tips will now be populated with whatever is in the column defined for the tool tips.

With these changes, the calendar takes on a more useful role, we can now use views we've already designed and just change the properties to match each view. But what if you want to design your own custom control to display data the way you want it displayed? In this case, we can use an Editable Area instead of putting all the data computation within a computed field on the calendar itself. This will allow us to put a custom control onto the editable area on the XPage instead of within the ccCalendar custom control. So, to support this, in the sample database (located in the downloads section) I've added another custom control called ccCalendarEditable. I've modified the dayCells computed field to only spit out the html to begin the column and include the number for the day and start the div which contains all the data for that particular day. We also changed the name of this computed field to beginTD. You'll notice also, that now the day is included within a span instead of a div and also that there is a function call that is within another span. I will get to this shortly.

I added another computed field named endTD which contains the code closing the column and data div.

Now, in between these 2 computed fields I've added an Editable Area and gave it a Name of calData and a Facet Name of calData:
EditableAreaOutline.jpg

When we drag this custom control (ccCalendarEditable) onto a new XPage I think I did find a bug which I discussed in my previous blog entry about being able to drop a custom control onto an editable area which is contained within a repeat. Since this is the case we'll have to hand code the embedding of the custom control I created to contain the data onto the facet within the XPage. This is a simple process and shouldn't cause too much headache. But, I created a new custom control called ccCalData. This control basically contains the code we removed from the dayCells computed field and put into a computed field on the ccCalData custom control. I did it this way to really just show the ability of being able to split up the data and design a little bit more. Also, please forgive my lack of a useful naming convention, since I'm just now really getting started with XPages I haven't really come up with a naming convention I use all the time. But to hand code the embedding of the ccCalData custom control onto the XPage this is the format. Notice the "xp:key" item defines the name of the Editable Area (calData in our case):

So, we now have 2 different ways to make our calendar more reusable. You can use @DbLookups to a view that you've already designed and just change the properties to return the data you want on the calendar or you can design your own custom control to drop onto the calendar. Also, in the case of this sample db the calendar should look at react exactly the same as it did when we left off with part 2. Either way makes this much more useful. Now, in preparation for having a "day view" and "week view" I've added a small drop down menu to allow you to switch views. Read on...


Continue Reading...

XPages question... Editable Area within a Repeat?

02/08/2010 3:05 PM By Keith Strickland

I've been working on making the Calendar Control more of a reusable control rather than using the @DbLookup calls within the ccCalendar control itself. For the most part, I've succeeded in doing this however before I publish it I need some information as it doesn't quite work the way I expect it to.

So, here's the scenario. I've busted the code within the dayCells computed field to only contain the beginning cell HTML, basically the opening TD call. I then added another computed field to handle the closing of the TD. Now, in between these 2 I've placed an editable area. This editable area shows up in the design mode for the ccCalendar Custom Control. Now, when we drag the ccCalendar custom control onto a new XPage, the editable area is visible however you can't drag another custom control onto it. When you try it drops the control above everything else. Also, when you look at the source for the XPage before adding a custom control onto the editable area, there is no xp:this.facets tag. Now I can add this tag manually and define the custom control I created just to display the data and it all works flawlessly but I don't like that I have to hand code it. But below is some screen shots and a short screen cast of the behaviour I'm attempting to describe:

EditableAreaOutline.jpg

Here is the control after I dropped it onto a new XPage. See the Editable Area is available:
EditableAreaDesign.jpg

Here is the entire source of the new XPage, notice there is no xp:this.facets tag:
EditableAreaSource.jpg

Here is the Screen Cast of what happens when you try to drop a custom control onto this editable area:

So, my question is this.... Should you add an Editable area within a repeat? If not, what is a better route?


SnTT: XPages Blank Calendar Control (Part 2), adding data

02/06/2010 11:18 AM By Keith Strickland

The other day I showed you how to make a custom control for an empty calendar. While neat it really isn't very useful unless you can put some data on it. So today's SnTT is to put some data on the calendar. Also, it seems there was a bug in the original code for the month "forward" and "back" links which caused the calendar to do some weird things, but no worries, that has now been fixed and is available in the download.

Now, on adding data. We're not concerning ourselves yet with durations, we'll have to tackle that later down the road and I'm sure I'll have to tap into some people who are smarter than myself. Right now we're only concerned with putting data within the appropriate day, having it formatted correctly and not enlarging the cell to fit the data but instead having a scrollbar available to scroll through the entries. We also want a dojo tooltip to show up when we hover our mouse over an entry so we can see any text that gets cut off. To accomplish this, the contents of a cell are made up of several divs. We use divs so that everything spans the entire width of the cell:

  • A div containing the number which is the day
  • A div containing all the entries for that day
  • A div for each entry
  • A div for the text of a tool tip

With our goal now defined we can start coding a little bit. I created a form called calEnt with just a few fields on it:

  • StartDate (we'll get to the EndDate/Time at some other point in the future)
  • StartTime
  • Subject
I also created a view called luDates with 4 columns:
  • StartDate - Sorted Ascending - This is text and not a date as it seems that the server side javascript @DbLookup can't lookup a date, it must be a string
  • StartTime - Sorted Ascending
  • Subject
  • Unique ID

Now we need to get some data and put it on the calendar. We'll do this in the computed field which we had named in our previous SnTT named "dayCells". To support this we had to add a couple of script libraries, one for Server Side Javascript and another for Client Side Javascript. The functions in the Server Side Javascript Library came from the article Work with DbColumn and DbLookup on the You at Notes website. I had to tweak the requestScope scoped variable check to also include the field (or in our case column) to ensure that there is 2 different requestScope variables. The functions in that library ensure that DbColumn and DbLookup calls are returned as an array, this is quite useful. The Client Side Javascript Library is for a function to handle the onClick event of a calendar entry. I'm not going to go into the code of these functions as they are available in the download.

In the dayCells computed field we start building the table cell with all the divs. Just note you need to change the view name with whatever view name you use in the DbLookupArray calls. You should end up with something like this:

Now we need a form to display our calendar entry in another custom control. This is just a simple form with 4 fields on it. I haven't really made it pretty or anything I just wanted to ensure that it worked, we can make it pretty later. So, I created a custom control with the same fields as the CalEnt form with the exception I added a computed field which contains the UNID of the document we're displaying. This is really just there for troubleshooting purposes but I thought I would list it to show how to get data from a parameter in the URL. I'm passing the UNID of the document we clicked on in the calendar to the URL because since we hand coded the div which contains the data from the view, client side javascript is used to navigate to the "entry" XPage via an onClick event, so we pass the UNID via an URL parameter:

We also need to bind our new custom control to the form. You do this in the Data section of the custom control:
BindAForm.png

And in the document ID field we add our param code again as Server Side Javascript:

You should now have a calendar that has data on it that is clickable which opens up the corresponding document. Next up is configuring our XPage so that the dojo tool tips pop up whenever you hover the mouse over an entry. So, since our calendar control is on the default XPage we need to set some properties here to make the dojo tool tips work. On the default XPage All Properties section of the XPage Properties, set the dojoParseOnLoad = True, dojoTheme = True. Also add a resource and pick dojoModule and for the name set it to dijit.Tooltip. Also under the styleClass property define Tundra as the styleClass. It should look like this:
calendar-dojo-properties.jpeg

And, that's it. You should now end up with this:
calendar-dojo.jpeg

I'm sure there is a better way to handle the binding of data to the calendar, but as I'm really just now starting to really delve into XPages I haven't quite figured out everything I can do yet. So, if you have a better way, please speak up.


SnTT: XPages Blank Calendar Control (Part 1)

02/04/2010 12:41 PM By Keith Strickland

While at LotusPhere I was searching for a way to create a Calendar using XPages to try and duplicate a Calendar View in the Notes Client. As I've said earlier, I believe this was a big part of XPages that was left out or just forgotten about. Well, I finally broke down and tried creating a Calendar Control on my own. Well I can't really say I did it on my own as I used the tutorials over on Declan's site and I had to enlist some help from Declan to solve a problem with the first row of the calendar. So, without further ado, let's get into it shall we...

First I had decided that I wanted to do this with a table instead of spans as it makes sense to do it that way as in my eyes that's what a calendar is, a table. Also I wanted to be able to navigate the months with links at the top of the table and maybe in the future a dojo calendar control somewhere. I've listed all the steps here in the order that I did things, while this may not make sense to some people it's what made sense to me. I guess I probably should've listed these steps in the order that they fall within the code, but I figured it best to go about how I did it. At the end of the article I will include all of the source code so it's just a copy and paste afair.

NOTE: Seems some of the strings within this document in the text areas are being screwed with for some reason. I will place an example DB in the downloads section shortly. Of particular note, the <[CDATA[ tags should read <[![CDATA

So, I started putting this thing together by starting with the Calendar table in a panel with the header and then the starting row of the actual calendar:

Next up is getting the blank cells that will appear when the starting date isn't a Sunday. This requires us to get some information when the page is loaded. We need to know what month, year, the day the 1st falls on and how many days are in the month. We do this with some viewScope variables in the "beforePageLoad" event of the control:

Once the blanks are figured out we just need to start filling in the blank days of the calendar. This is just a computed field inside a repeat function:

Now we need to cycle through the days and place them within a TD and include the day number. There are a couple of things of special note here.

  1. The computed field that adds the closing and opening tags for the rows, this needs to come BEFORE the first entry of the week, NOT AFTER!
  2. In the computed field that puts the day number in the cell, you need to add 1 to the day because the days are zero based. If you don't do this the first will actually read zero
  3. Also, we don't need any logic to figure out the contents of the cell since we're determining if a new row is needed in the first computed field within this repeat

Last part of the calendar table is the blank days after the end of the month when the last day isn't on Saturday and then close the final row of the table. This is accomplished with another repeat control and a computed field:

Finally we need to add a Title Header to the top of the calendar to show the month and then a couple of links to navigate forward and back. This is accomplished using 2 links and a computed field. The month which is displayed in the computed field is determined from the contents of an array which contains all the months and we then use the viewScope.dispCalMonth variable minus 1. The links change the viewScope variables to use the correct date. All of this is placed inside a panel:

Now, to put all of this together:

So, I hope you find this control useful. The next steps (which I haven't quite figured out yet) are to put some data from a view onto the calendar and to add some more functionality to try and match that which is found in a notes calendar view. I am also wanting to put a calendar control somewhere on the page so you can pick a particular date that may be more than a year or so in the past/future.

UPDATE: OK, I think I've got all the formatting stuff fixed. I had to use HTML Encoding on all the items. I'll still put an example db in the downloads section. I also added a screen shot to the read more section.


Continue Reading...

XPages development helps in other places too...

09/08/2009 3:17 PM By Keith Strickland

I know it's been a while since I've posted anything, but I've been rather busy (understatement) here lately. But I've been doing some PHP development for one of my other customers and I've been incorporating DoJo dialogs and tool tips in various places throughout his site. While messing with a lot of this I found myself going through some of the code that gets generated when incorporating tool tips and dialogs into an XPage as a reference. If it weren't for me going through the XPages Tooltip tutorial over on Declan 's blog I never would have even been aware of something such as Dojo even existed.

So I would like to Thank Declan for the outstanding tutorial and also for making me aware of Dojo which allowed me to make a customer very happy and hire me for more development projects. Thanks Declan!


XPages Type Ahead and Multiple Values frustration

07/25/2009 1:22 PM By Keith Strickland

Here's the scenario. I've got an edit box which holds multiple names, when the page is in read mode I can display those names separated by a new line "\n". However, I'm wanting to use the type ahead functionality to pick multiple names, which isn't a problem. The problem is I can't figure out how to get the names selected from the picker to show in the field separated by anything other than a comma and all on one line, which makes it impossible to see what values are in the field. I've tried the Multilne Edit Box but you can't use type ahead functionality with that control. I've tried all different kinds of things with the Suggestions Separator and Client Separator properties, the edit box's multipleSeparator property and using some javascript to change how it displays, the only result I get is that the type ahead stops working, there are no errors just no type ahead.

Don't get me wrong here, I've totally enjoyed delving into XPages, but it's little things lke this that really frustrate me. Something that is so polished and fairly easy to get used to there seems to always be these little gotcha moments along the way

Rant off


XPages Domino Directory Type ahead

07/22/2009 8:38 PM By Keith Strickland

As I said earlier, I've been delving into XPages here lately and found the cool "Type Ahead" properties of an editable field. This is so easy to implement and comes out looking nice to boot. To add a name picker to your application follow these procedures. Now I'm sure there are other ways to accomplish the same thing, but this is pretty darn easy.

Go to one of your name fields and in the properties select the "Type Ahead" entry. Check the "Enable Type Ahead" check box. Add the proper separators and click the blue diamond next to Suggestions and pick "Compute Value". In the resulting javascript editor put the following code and click OK:

var dbname = new Array(@Subset(@DbName(), 1),"names.nsf");
return @DbColumn(dbname,"($VIMPeopleAndGroups)",2);
You should end up with something like this:

2009-07-22_2042.jpg

Now save the page and visit the page in your browser, start typing LocalDomain and you should see the selections show up below the field. Like I said, easy peasy.

2009-07-22_2044.jpg

XPages experience and resources

07/19/2009 9:24 AM By Keith Strickland

I've recently started messing with XPages and I think I like it. Now there is a rather steep learning curve for XPages, especially if your web development hat is as dusty as mine. I even had to bust out the "Beginning JavaScript" book by Paul Wilton (which is an excellent JavaScript reference). But learning them is certainly doable, and quite fun (in a geek sort-of way). But this trek started with an OpenSource project I've been working on which I mentioned a little over a month ago. I want a web gui to go with the project so I figured it was the perfect excuse to delve into XPages head first.

My first impression with XPages seems to be pretty good, it's easily implemented, looks nice and easily compartmentalized (is that a word?). As I said above the learning curve is pretty steep and when using the @Functions it is easy to make a mistake, since those are now serverside JavaScript it is case sensitive. I've also noticed any bad habits you have with using LotusScript and @Formulas that those bad habits really come back to bite you as you try to use that knowledge in the XPages world. As for all the controls, it seems that everything I've needed has been there in some form or fashion. My biggest issue so far has been trying to figure out how to use a checkbox. In the notes client a checkbox is a multi-value field with each value being a checked checkbox, in XPages they are individual elements and a field with values already there doesn't seem to translate over, at least I haven't been able to figure out a way yet, but I'm sure it's there somewhere. Radio buttons are similar but a little easier to figure out.

But something that has provided A LOT of help is the excellent XPages tutorial over on Declan Lynch 's site. This is a great reasource to get you moving in the right direction. Thanks Declan! Interestingly enough though there is no mention of how to use Check Boxes or radio buttons in this tutorial or any of the other tuturials I've come across.

Some other resources I've found are listed below:

I guess the biggest complaint I've had with this process is the quirks of the 8.5 designer. The double-clicking to open a design element is killing me. Also, sometimes it takes 4 clicks to get a group of design elements (say XPages) to open and show the XPages in that group. I know that isn't a very good description of what I'm talking about. But hopefully the resource list above will get you on your way to starting XPages. I am by no means really knowledgeable enough to really speak about XPages in any way other than my experiences so far, but this trek should be something new and interesting and produce some really nice applications. Plus it seems that this is really the next logical step for Domino development.


Subscribe to keithstric.com

OpenNTF

Disclaimer

The opinions and ideas posted on keithstric.com are not necessarily the opinions and ideas of my employer. The solutions, techniques and code provided here are not guaranteed or warranted in any way and are free for you to use at your own risk.