wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

Partial Page Rendering in XPages


More goodness coming along in XPages 8.5.2 (Disclaimer: it is still Beta ...) An XPage is a collection, or to be precise, a tree of controls with an xp:view tag as root control. The xp:view tag translates into a instance of the UIViewRootEx2 class. In theory you could subclass this but then you stray far away from the path of IBM support. In some case (think Ajax updates) it would be nice if you could request the render result of just one control (and all its children of course). In 852 this is possible using the ?$$axtarget= directive. It takes the client id as parameter and requires a keyword (you can use to identify the action) between page name and directive. So your URL could look like this:
http(s)://[yourserver]/[application.nsf]/[Yourpage.xsp]/[SomeactionName]?$$axtarget=[ClientIDofTheControl]
The control doesn't need to check for the value of [SomeactionName], it is up to you if you want to use that. A sample function giving you the url for a given command and control could look like this (you want to add error handling for production use):
  1. function getSpecialAction (actionName , componentName ) {
  2.     var toRenderPartial = getComponent (componentName ) ;
  3.     return 'myPage.xsp/' +actionName + '?$$axtarget=' +toRenderPartial. getClientId (facesContext ) ;
  4. }
As usual YMMV

Posted by on 25 June 2010 | Comments (6) | categories: XPages

Comments

  1. posted by Jeremy Hodge on Saturday 26 June 2010 AD:
    omg, i think i just peed a little...

    ... and commence happy dance

    I heard something like this was possible, but hadn't been able to find it.
  2. posted by Sean Cull on Saturday 26 June 2010 AD:
    Stephan, what would be a real world use of this with reference to a discussion database or something similar ?

    Thanks, Sean
  3. posted by Tommy Valand on Saturday 26 June 2010 AD:
    To capture/react to the event, do you have to add an event handler to the target control, or can you listen globally for these events?

    If it's the latter, then we're close to having dynamic event binding, and custom events in XPages. Something I've wished for since the first time I got my hands dirty with XPages :)
  4. posted by Jeremy Hodge on Saturday 26 June 2010 AD:
    Off the bat, the couple of things I want to do with this is:

    - XPages Widgets! Now you can have an object that can generate html fragments that can be consumed and placed into non domino websites

    - Dynamic runtime selection and addition of XPage elements to an existing XPage via an xhrGet/xhrPost ... almost like computed subforms.

    - I have to play with this to see if its all going to work the way I think it might, but it would allow you also to write complex XSP agents with multiple functions within a single page, ie an API ... for example, instead of setting your view root to render="false" you can call this page (maybe named api.xsp) and based on the [Someactionname] and the axtarget you could output different responses in different formats, for example:

    - YOU CAN MAKE XPAGES GENERATE VALID XML! For example, an XPages based RSS feed ... you could point the call to a repeat control, use the xp:facets for header and footer and wallah ...

    - Or just about any other format of a file you wanted ... conceptually, you could create dynamically created json objects, etc etc

    my head just 'sploded
  5. posted by Jeremy Hodge on Saturday 26 June 2010 AD:
    I should mention, its this: { Link } in combination with this capability is what makes everything so possible...
  6. posted by anonymous on Saturday 02 July 2011 AD:
    Has anyone got a good example of hooking into this? My trials have only seen the afterRestoreView events being triggered and I can't modify the response body.