A Quick-and-Dirty "$$ViewTemplateDefault" (-ish) for XPages

May 3, 2012 8:16 PM

Tags: xpages

8.5.3 brought with it the very-handy "Display XPage Instead" property for views. It's great! That way, you can keep more of your existing URLs in old apps or just generally use cleaner ones in new apps - XPages are awesome, but ".xsp" in the URL is not.

In a full-blown app, you're probably going to point each view to its own XPage containing the hand-crafted fancified version. Sometimes, though, you just want to toss a xe:dynamicViewPanel on a page and that's good enough. However, unlike with the equivalent property for Forms, you can't just put a xp:dominoView data source on the page and have it pick up the view the XPage is replacing. With a Form replacement, the server translates a URL like "/view/document" to "/page.xsp?documentId=whatever&action=openDocument" for you; for a View, however, all you get is "/page.xsp". This stymied me when I just wanted to make a generic "View.xsp" to use as scaffolding for new views until I make a real page for each one.

Fortunately, though context.url (context.getUrl() in SSJS) shows the XPage path, you can use a longer property facesContext.externalContext.request.requestURI to get the original request's path info (the part after the server name - the other components are also available in that object). You can use that to fetch what's to the right of the database name (you could use ".nsf/", but facesContext.externalContext.requestContextPath + "/" would probably be technically safer in edge cases, assuming you can use ".nsf" in a folder name on a Domino server) to get the view name (extra line breaks for display purposes):

<xp:dominoView var="dbView">
			+ "/"), "UTF-8")

Not beautiful, but it works. With that and a xe:dynamicViewPanel, you can get a sort of $$ViewTemplateDefault replacement, though you still have to specify it for each view.

Commenter Photo

Nemu - May 8, 2012 6:52 AM

The best solution to let a dynamicViewPanel open the corresponding XPage would be to set it right in the Form.

You can do this in the Form Properties, under On Web Access to Display Xpage instead to the corresponding XPage.

The Link will look a bit like this \OpenDominoDocument.xsp?openXPage&documentId=UNID

this will work both in Notes Clients as well as Web Clients, and you wont need to worry about Decoding the URL anymore.

Commenter Photo

Jesse Gallagher - May 8, 2012 7:18 AM

That definitely works well for forms, but in my experience it didn't work to set that for the $$ViewTemplateDefault form - the server doesn't seem to "chain" the misdirections enough, but instead just shows the actual form contents when hitting the view. I guess I didn't try it for "$$ViewTemplate for SomeView"-style ones, but I assume it works the same.

New Comment