The Data Table uses a simple table structure to display content. The table is configured to contain three row elements, such as a header, a content row, and a footer. The header and footer typically contain static elements, such as column titles, pagers, or just arbitrary one-off control instances. The content row usually contain a collection of individual controls that are bound to elements of a data source, and this row is then rendered repeatedly for each entry in the data source (once for every row in a view) when the Data Table is invoked as part of a live application.
Unlike a View Panel, however, all the controls contained in the Data Table must be added and bound manually, and certain other capabilities are simply not available, e.g. categorization. In essence, it is like a dumbed-down View Panel control, but it can be useful if you need to display simple nonhierarchical data in a customized fashion. You see an example of a good use case in this section.
To start with, try to present a regular view using a Data Table to get familiar with its features and behaviors. You should create a new XPage, say myDataTable.xsp, and drag-and-drop a Data Table control from the palette. Compared to the View Panel drag-and-drop experience, you might be underwhelmed with results. Basically, a shell of a table is created, and it's pretty much up to you to populate it with controls and bind these in a meaningful way.
Designer prompts you that a data source needs to be created if one does not already exist on the page, so for the purposes of this example, you should create a view data source targeting the xpAllDocuments view. This can be done in a number of ways, such as from the Data property panel on the XPage itself or using the Define Data Source combo box entry on the Data palette data source picker. Whatever your preferred route might be, simply pick the aforementioned view as the data source. Even though you now have a page containing a Data Table and a view data source, they are not connected and know nothing about each other. You can wire these together using the main Data Table property panel, as shown in Figure 9.22.
Figure 9.22 Connecting a Data Table to a view data source in Designer
Figure 9.23 Binding a Computed Field to a view data source element in Designer
The EL data binding markup generated by Designer has the following form. The name of the column is provided as a key to the row data entry:
You should also drop two Label controls from the palette directly into the two cells in the top row of the Data Table and change their values to Date and Topic, respectively. You can also assign the Data Table a width of 600 pixels for quick aesthetics using the Width and Units controls shown in Figure 9.22. After you complete this step, you are ready to preview or load this Data Table. The results should be just like the page you see displayed in Figure 9.24.
Figure 9.24 Data Table displaying data from xpAllDocuments view
The Data Table could do with a pager to split the rows into manageable chunks. The first step is to set the rows property of the Data Table to smaller number than its default value of 30 (for example, 10). Interestingly, the pager you have worked with up to now in the View Panel is not an intrinsic part of that control, but an independent entity that can be used with any of the view controls. The View Panel just happens to include a pager instance by default. To add a pager to the Data Table, look for the Pager control in the Core Controls palette and drag it into one of the footer cells. Then, activate the Pager property panel and attach it to the Data Table by picking the ID of the Data Table from the Attach to combo box—where Designer kindly enumerates a list of eligible candidate controls for you! At the same time, turn on partial refresh so that paging updates are performed using AJAX. The various property panel selections are shown in Figure 9.25.
Figure 9.25 Pager property panel
Because the Pager is capable of working with any view control, you must nominate a target container. The Partial refresh checkbox selection instructs XPages to update just the targeted view control via an AJAX request when a pager action is executed. This means that only the view data in the Data Table is refreshed when the end user navigates from one page to the next, which is obviously more efficient than refreshing the entire page every time.
The only problem with the pager right now is that it resides in the wrong place. It has been dropped into the footer cell of a column when it really needs to be in the footer of the Data Table itself. Unfortunately, the footer of the Data Table is not an identifiable drag-and-drop target in Designer, so you must go to the Source pane move the markup manually. Simply cut and paste the entire <xp:pager> tag from its current location so that it is a direct child of the Data Table. It should also be wrapped in a <xp:this.facets> tag—see the final markup in Listing 9.7.
Domino developers no doubt are familiar with the @Now() function, which returns the current data and time. The getMilliseconds() call expresses the time in milliseconds when the page is loaded. When you load or preview the page, both fields should display the same number. If you start navigating through the view data using the navigator, you notice that the Computed Field within the Data Table is updated with the current time milliseconds value while the field external to the Data Table is not. This demonstrates the efficient behavior of the partial refresh feature.
Figure 9.26 shows the updated XPage in action. The full markup is done for you in the dataTable.xsp XPage in Chapter9.nsf and is printed in Listing 9.7.
Figure 9.26 Data Table with partial refresh paging enabled
Listing 9.7. XSP Markup for SampleData Table
Although working with the Data Table may be vaguely interesting, it must occur to you that what you have just built could be achieved using a View Panel control in a fraction of the time with just a few point-and-click operations. So, why bother with the Data Panel at all? The answer is that the Data Panel can be useful when you want to build a small bare bones tabular view with a highly customized user interface. Perhaps these use cases are not commonplace but they do occur. The next exercise serves as a good example.
Building a Mini Embedded Profile View using a Data Table
Carry out the following steps, drawing on what you learned in the current section up to this point:
- Create a new XPage called dtProfile.xsp and add a Data Table from the palette.
- Create a view data source targeting the xpAuthorProfiles view.
- Connect the Data Table to the data source and set its Collection name to "rowData" in the Data Table property sheet. This should result in a var="rowData" attribute being created in the underlying <xp:dataTable> tag.
- Append two new columns to the Data Table using the right mouse menu.
- Add a Computed Field to the 1st content cell; that is, first column, middle row.
- Add a link control for the palette to both the 2nd and 3rd cells in the content row.
"mailto:" + rowData.getColumnValue("Email")
- Set the label for the second link to "Download" and compute its type in the same way as before, this time building a Domino resource image URL like this:
"/" + rowData.getUniversalID() + "/$FILE/" + rowData.getColumnValue("FileUpFilename")
- Drag-and-drop an image control to the fourth and final content row cell, using the Use an image placeholder radio button for now so that you can compute the image reference.
- For presentation purposes, select the All > Style cell in the property panel for each Data Table column and set this CSS rule:
- In the same way, set the All > Style property for the Data Table itself to this:
You already practiced most of the 13 steps in one way or another when working through View Panel or Data Table examples, so only a few steps need any further explanation.
where the first part is an ID to identify the document to use, the second part indicates that the URL represents a file attachment resource, and the third part is the name of the attachment. This form of URL has been used in classic Domino web development for a long time. Back in Chapter 3, you learned about special IDs that Notes maintains to manage its databases and documents. The universal ID (UNID) is a 32-character hexadecimal representation that uniquely identifies a document. The profile documents in the Discussion template each contain a single image (or placeholder image) of the author and the name of this image file can be obtained from the FileUpFilename column in the xpAuthorProfiles view. Thus, a resource URL can be dynamically constructed for all registered users and this URL resolves the image and retrieves it from the profile documents for display in the Data Table. An example of a real live resource URL is highlighted in the status bar of the browser in Figure 9.27.
Figure 9.27 My Profile Page with Embedded Data Table
You are now ready to preview or load the new XPage. Chapter 9.nsf contains some sample profile documents, so you see these listed in the Data Table. The actual intention, however, is to display this Data Table as an embedded view in the My Profile page. To do this, you need to open the authorProfileForm custom control and copy/paste the markup from dtProfile.xsp to the bottom of the XPage, just before the final </xp:view> tag. Naturally, you do not copy the <xp:view> tag from dtProfile.xsp but just the Data Table and data source markup—everything you see in Listing 9.8. Figure 9.27 shows a snapshot of a My Profile page from Chapter9.nsf.
Listing 9.8. Data Table Displaying Profile Data
Had you used a View Panel for this particular use case, you would have had to undo a lot of the features it gives you for free, such as pagers, column headers, and so on. You would also have had to customize the columns to display HTML and then return link and image HTML elements for three of the four columns. The Data Table actually simplifies the process by allowing you to drag-and-drop and arbitrary control into any content row cell and then just compute its value.
Another good example of Data Table usage is the File Download control. This out-of-the-box control is really a Data Table that has been adapted by the XPages runtime to display a simple table of any attachments contained in a nominated rich text field. Figure 9.28 shows the File Download control displaying some attachments in the Discussion application—it should be easy to see how this was built, given what you have just done to implement the embedded profile Data Table.
Figure 9.28 Example of the File Download control in the Discussion application
That is the Data Table, all done and dusted!