PermaLink XPages: Generate Dynamic Views at runtime - Custom Control....opinions wanted01/28/2010 08:04 AM
Domino 8.5 - XPages
I was working on an application where I had a number of views on an XPage that I would hide/show depending on the navigation selected.  I thought it would be great not to have to embed every view on the page, plus build out all the XPages views.

Just for fun I looked into creating a custom control that would accept the view name, the columns/fields, the link to open, etc. as parameters. The custom control would then generate the view for me. It turned out not to be so difficult to build...at least a scaled down version of a view control.

There's more to do though, but I was curious before I put more time into this if this is something folks could use?  Please comment and let me know if you could use something like this and I'll finish it and publish it on openNTF.org.  You can try out the example here: Dynamic View Custom Control

Here's a screen shot of it in action.  The top section is for demo purposes only.  The view name, columns, etc., can be passed via scope variables (or anyway you want).  There might be a use case to allow users to save their view preferences in a profile or config document.  (the data in the example db is garbage, that's why it looks to be duplicated):

Image:John's Blog - XPages: Generate Dynamic Views at runtime - Custom Control....opinions wanted

So far, here are the parameters that I pass to the custom control.
Image:John's Blog - XPages: Generate Dynamic Views at runtime - Custom Control....opinions wanted

The custom control uses nested repeat controls to build the view.  I used Paul Calhoun's example Creating a Dynamic HTML Table on an XPage to add the columns to the tables as it iterates through the field list.  By adding the <xp:td> tags around the repeat controls the Outline palette seemed to object to this and will not let me select the repeat control anymore with my mouse.  I have to work on that because it's torture to work with like this....

Here's a screen shot of the custom control with the nested repeat controls.  Not much to it.  Right now I'm being challenged to add a sorting feature to the columns.  Any ideas?:
Image:John's Blog - XPages: Generate Dynamic Views at runtime - Custom Control....opinions wanted

-John

Technorati:
This page has been accessed 5297 times. .
Comments :v

1. Paul Withers01/29/2010 04:21:07 AM
Homepage: http://hermes.intec.co.uk/intec/blog.nsf


One of my frustrations with XPages v classic notes-for-web development is that XPages is intended to separate data from presentation. With classic notes-for-web development, you can have one $$ViewTemplate (or one for multiple views). However, with XPages, if you're showing views with different columns or columns in a different order, you need separate custom controls. This is a great idea for allowing user flexibility but could also be extended to pull from a database config, one of the ideas I've not had a suitable project to pursue.

For sorting, can you use the sortColumn and sortOrder properties of the DominoView? The problem is I've never been able to work out or find examples to see what values these properties expect to receive. The other problem is I think you would need to enable sorting on all columns in your Notes View, which could have performance impacts.

An alternative would be to have copies of the views sorted on the different columns, and switch the view based upon which column they want to sort (e.g. if sort is City, switch to a view myViewCitySort instead of myView)




2. Steve Castledine01/29/2010 04:25:56 AM
Homepage: http://www.stevecastledine.com


I do have a custom control that you just give the viewname to and it builds the view ala $$ViewTemplate - just needs some finishing off which I will do very soon and then upload to OpenNTF. It uses existing view design properties as well to determine whether to show columns or not




3. John Turnbow01/29/2010 04:35:23 AM
Homepage: http://www.recondite2.com


Very nice.. I think there would be a need to choose where each field shows up in the view as well, not just select. I would like the Customer Name to be in the first column but could not move it there. Do that and you've got a great control.




4. John Mackey01/29/2010 05:07:00 AM


Thanks for your comments.

@3, that's just a limit on my demo and the checkbox selection I use. You actually list the fields in the order you want and pass them separated with ";". Example: customername;address;phone

@1, it does use the sorted order of the view you selected. I'd like to offer the user a clickable title. I guess to build on your point, I could switch views when the user clicks on a column.

@2, I am curious to see how you incorporate the $$ViewTemplate




5. Mark Hughes01/29/2010 08:13:52 AM


why not just have a computed view data source, and compute based on scope variables, column values, hide when and stuff like that? I guess that is in a sense what you are doing anyway.




6. John Mackey01/29/2010 09:59:57 AM


@5, Mark that's an interesting idea. Calculate all columns in a view plus the datasource. I guess I could set 10 columns and hide the additional ones that have no field assigned. I'll test that out...thanks!

John




7. Steve Smillie01/29/2010 12:54:46 PM


Just like @1, I had the same thought and I even asked that question on the 8.5 Beta forum long ago.
The answer was one XPages per view.

When converting existing Domino apps that used a $$ViewTemplate to XPages, you replaced one form with many XPages/Custom Controls.

I like the idea @1 of expanding that custom control by pulling from some database config.

I definitely would have interest in a custom control like your working on.




8. Martin Rowland02/12/2010 09:49:41 AM


It would be great if you could make that custom control available on openNTF




9. John Mackey02/13/2010 05:40:41 AM


@8. Martin, I'm almost done with it and will be posting it on OpenNTF soon.

-John




Search
Partner with us
Need help on your XPages projects?

Talk to the experts! Read more...
XPage Examples
By Category
About Me
Downloads
My Links
Monthly Archive
Powered by
Blogsphere
Lotus Domino ND7 RSS News Feed RSS Comments Feed Geo URL netcraft RSS Validator Lotus Geek Chris. A. Brandlehner OpenNTF BlogSphere