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.

« iPad thoughts... | Home Page| SnTT: XPages Blank Calendar Control (Part 2), adding data »

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.

xpages-calendar.jpg

Comments

ID: 1
Date: 02/04/2010 07:57:57 PM
Name: Jeremy Hodge
Website: http://www.hodgebloge.com

Keith,

Thanks for sharing !! I was just going to start putting together something like this myself tomorrow, and you have provided a great start for me. Thanks again.

ID: 2
Date: 02/05/2010 07:04:06 AM
Name: John Mackey
Website: http://www.jmackey.net

Very nice Darren! I know I could use this. Thanks for posting it.

-John

ID: 3
Date: 02/05/2010 09:20:20 AM
Name: John Mackey
Website: http://www.jmackey.net

Keith, I apologize that I called you Darren.Emoticon I was reading too many posts this morning...

-John

ID: 4
Date: 02/05/2010 10:32:34 AM
Name: John Palmer
Website: http://www.heyheyjp.com

Keith:
Just talking about lack of XPages calendar and our need for one and BANG - look what shows up! Nice start! Now to figure out how to JUST point it to a view and have it pop in the data.

ID: 5
Date: 02/05/2010 01:14:57 PM
Name: Paul Withers
Website: http://hermes.intec.co.uk/intec/blog.nsf

Great work, it's looking good. It was a topic I started thinking about before Christmas. The challenge I identified, as you say, is putting data in the boxes, scrolling if you have too many entries, allocating against times and ranges of times etc. At that point I decided it was something for another day!
After a tweet I was pointed in the direction of Flex as an alternative method of putting together a calendar view control (the example I saw was very rich in functionality), but again I never got round to investigating further to see how easy it was in that technology.

Post A Comment

:-D:-o:-p:-(:-):-\:-|:angry::cool::cry::dontknow::emb::hairout::laugh::rolleyes::whew:;-)

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.