PermaLink XPages Dynamic View Custom Control - on OpenNTF.org02/16/2010 03:46 AM
Domino 8.5 - XPages
I created an XPages custom control that dynamically builds a view based on a series of passed in parameters.  Normally with XPages, if you want different views to be displayed on your XPage, you would create the multiple view controls and hide the ones that should not be displayed.  This custom control allows you to drop a single CC on your XPage and it can generate the views for you.  Cick here to open the OpenNTF.org project.

Overview

I included a sample page and test data so you can try the Custom Control out.

When you first launch the database, click on a view to generate: Projects, Customers, or Orders.

Image:John's Blog - XPages Dynamic View Custom Control - on OpenNTF.org



When you click on one of the view links I set session scope variables for the view parameters.  You can pass these parameters anyway you like or compute them too. For the demo I chose session variables. You can even build an interface so the users can tailor their own views.  Here's a sample of setting the parameters for the Project view:

Image:John's Blog - XPages Dynamic View Custom Control - on OpenNTF.org



On the Custom Control, you can see how I pick up the Session Variables and pass them to the control:

Image:John's Blog - XPages Dynamic View Custom Control - on OpenNTF.org



To further demonstrate how you can change the view dynamically, I added a custom control that has input controls bound to the session variables.  This allows you to change any of the parameters and click the "Build View" button to regenerate the view.  So you can change the order of the fields, the width of the view, link column etc.,  

*Note: the fields do not have to be physically in the view.  I grab the fields from the backend document:

Image:John's Blog - XPages Dynamic View Custom Control - on OpenNTF.org


The ccDynamicView control is actually very small.  It consists of 2 nested repeat controls with a pager control:
Image:John's Blog - XPages Dynamic View Custom Control - on OpenNTF.org


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. This makes it difficult to edit the custom control through the interface. If you need to make changes, you need to use the source view.

This repeat control builds the columns and the view header by exploding the list of columns and iterating through them:

        <xp:tr>
                        <xp:repeat id="repeat2" rows="30"
                                value="#{javascript:@Explode(compositeData.columns)}" var="colName"
                                indexVar="colIndex" first="0">
                                <xp:td>

                                        <xp:text escape="true" id="computedField1"
                                                value="#{javascript:colName;}"
                                                style="color:rgb(0,0,128);font-weight:bold">

                                        </xp:text>
                                </xp:td>
                        </xp:repeat>
                </xp:tr>


The next repeat control retrieves the data set for the view depending on the fulltext and category parameters, and then retrieves the field values for document.  Along the way it formats the rows for alternating color and builds the href links.


Cons
On the downside to using this custom control, the view cannot be expanded and collapsed.  Nor is their the ability to click a column heading and sort the data.  If anyone knows how to add that feature please comment!  

-John


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

1. Frank van der Linden02/16/2010 06:48:51 AM
Homepage: http://www.domino-weblog.nl


Nice work.
1 question, for what purpose is the parameter 'xpageName'??




2. John Mackey02/16/2010 06:54:17 AM


@1, thanks Frank. The xpageName is used to identify what XPage you want to open the document in. I use it when building the href link for the view column to read/edit the document.

The parameters are documented in the OpenNTF.org project.

-John




3. Paul Withers02/16/2010 08:43:49 AM
Homepage: http://hermes.intec.co.uk/intec/blog.nsf


Thanks John for another excellent tool. I'm sure it will get plenty of use.




4. Mark Hughes02/16/2010 09:42:54 AM
Homepage: http://hughesconnect.com


Very clever, how do you come up with this stuff?

Great work once again, i really enjoy your articles.




5. Paul Calhoun02/26/2010 12:34:34 PM
Homepage: http://www.nnsu.com


John,

Once you compute the categorized view column you lose the expand/collapse. To get it back switch to the all properties view of the view column and add the column name back to the columnName property under the basics section.

If it's a view column you should get the expand collapse back. Not sure about the sorting but working on it.




6. chenybin04/07/2010 10:12:23 AM


if the view has catagory column,have any suggestions?




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