Home > Articles > Mobile Application Development & Programming

This chapter is from the book

Data Table

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

Figure 9.22 Connecting a Data Table to a view data source in Designer

With the Data Table entry selected in the Outline view, pick the newly created view data source instance ("viewAll") using the Data source combo box, and you also need to enter a Collection name. The collection name, "rowData" in this example, is used as the object to gain programmatic access to each row entry as it is being rendered—just as it was in the View Panel examples earlier. Rather than use server-side JavaScript in this case, however, you could just use simple Expression Language (EL) bindings. First, however, you need some controls to display the row data, so drag-and-drop a Computed Field from the Core Controls palette to the first cell in the middle row and then repeat the process for the adjacent table cell. These Computed Field instances can be selected and bound using EL expressions—or Simple data binding, as it is described in Designer's Value property panel and displayed in Figure 9.23. Bind the first field to the _MainTopicsDate column and the second field to the _Topics column.

Figure 9.23

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:

#{rowData['_MainTopicsDate']}

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

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

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.

To best illustrate the effect of the AJAX partial refresh, however, it is worthwhile adding two more Computed Fields to the XPage. Place the first Computed Field in one of the Data Table footer cells and then the second control can be dropped anywhere else on the page as long as it is outside the Data Table. Then, add the following server-side JavaScript as the computed value for both fields:

@Now().getMilliseconds();

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

Figure 9.26 Data Table with partial refresh paging enabled

Listing 9.7. XSP Markup for SampleData Table

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
      <!-- The data source defined at root level -->
      <xp:this.data>
            <xp:dominoView var="viewAll"
                  viewName="xpAllDocuments"></xp:dominoView>
      </xp:this.data>
      <!-- The data table finds the data source using value prop -->
      <xp:dataTable id="dataTable1" rows="10" var="rowData"
            value="#{viewAll}" style="width:600px">
            <xp:column id="column1">
                  <!-- column header and footer entries -->
                  <xp:this.facets>
                        <xp:label value="Date" id="label1"
                        xp:key="header"></xp:label>
                        <xp:label value="Internal Time Value"
                        id="label3" xp:key="footer"></xp:label>
                  </xp:this.facets>
                  <!-- Bound to the date field using EL -->
                  <xp:text escape="true" id="computedField1"
                        value="#{rowData['_MainTopicsDate']}">
                  </xp:text>
            </xp:column>
            <xp:column id="column2" style="width:300px">
                  <xp:this.facets>
                        <!-- column header and footer entries -->
                        <xp:text escape="true" id="computedField3"
                        xp:key="footer"
                        value="#{javascript:@Now().getMilliseconds();}">
                        </xp:text>
                        <xp:label value="Topic" id="label2"
                        xp:key="header"></xp:label>
                  </xp:this.facets>
                  <!-- Bound to the Topic field using EL -->
                  <xp:text escape="true" id="computedField2"
                        value="#{rowData._Topic}">
                  </xp:text>
            </xp:column>
            <xp:this.facets>
                  <xp:pager layout="Previous Group Next" id="pager1"
                        for="dataTable1"
                        xp:key="footer"
                        panelPosition="left"
                        partialRefresh="true">
                  </xp:pager>
            </xp:this.facets>
      </xp:dataTable>
      <!-- Table only used for layout alignment -->
      <xp:table style="width:600px;text-align:left">
            <xp:tr><xp:td>
                  <xp:label value="External Time Value"
                        id="label4">
                  </xp:label></xp:td>
                  <!-- external computed field -->
                  <xp:td style="width:300px; text-align:left">
                        <xp:text escape="true" id="computedField4"
                        value="#{javascript:@Now().getMilliseconds();}"
                        style="text-align:left"></xp:text>
                  </xp:td>
            </xp:tr>
      </xp:table>
</xp:view>

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:

  1. Create a new XPage called dtProfile.xsp and add a Data Table from the palette.
  2. Create a view data source targeting the xpAuthorProfiles view.
  3. 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.
  4. Append two new columns to the Data Table using the right mouse menu.
  5. Add a Computed Field to the 1st content cell; that is, first column, middle row.
  6. Bind this field to the From column in the data source using JavaScript:
    rowData.getColumnValue("From")
  7. Add a link control for the palette to both the 2nd and 3rd cells in the content row.
  8. For the first link, activate the Link property panel and set the Label and Link type fields. For the label, enter "email" in the edit box, and then for the latter, add some server-side JavaScript to compute a URL. This is a mailto URL, created by simply concatenating a "mailto:" to the Email column value, as follows:
    "mailto:" + rowData.getColumnValue("Email")
  9. 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")
  10. 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.
  11. In the Image property panel, compute the Image source using exactly the same server-side JavaScript as previously shown.
  12. For presentation purposes, select the All > Style cell in the property panel for each Data Table column and set this CSS rule:
    text-align:center; vertical-align:middle
  13. In the same way, set the All > Style property for the Data Table itself to this:
    width:400px;

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.

Step 6 simply returns the name of the author of the document. This is in Notes canonical form, so it would be more natural to present the common user name in this column instead. Experienced Domino developers instinctively know to do this using the @Name @Function, which can reformat Notes names in a number of ways. Although @Functions and other traditional building blocks are covered in more detail in Chapter 11, "Advanced Scripting," in the section, "Working with @Functions, @Commands, and Formula Language," it is no harm to start dabbling with some simple use cases at this stage according as the need arises. To do this, simply wrap the JavaScript binding command in with an @Name() call:

@Name("[CN]", rowData.getColumnValue("From"));

Step 9 uses JavaScript to build a Domino resource URL. The generic form of this URL is

/UNID/$FILE/filename

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

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

<xp:this.data>
      <xp:dominoView var="view1" viewName="xpAuthorProfiles">
      </xp:dominoView>
</xp:this.data>

<xp:dataTable id="dataTable1" rows="30" value="#{view1}"
      var="rowData" style="width:400px">
      <!-- style each column like this -->
      <xp:column id="column1"
            style="text-align:center; vertical-align:middle">
            <!-- get the common user name -->
            <xp:text escape="true" id="computedField1">
                  <xp:this.value><![CDATA[#{javascript:
                  @Name("[CN]", rowData.getColumnValue("From"));
                  }]]></xp:this.value>
            </xp:text>
      </xp:column>
      <xp:column id="column2"
            style="text-align:center;vertical-align:middle">
            <!-- return a mailto link -->
            <xp:link escape="true" text="e-mail ..." id="link2">
                  <xp:this.value><![CDATA[#{javascript:"mailto:" +
                  rowData.getColumnValue("Email");}]]></xp:this.value>
            </xp:link>
      </xp:column>
      <xp:column id="column3"
            style="text-align:center; vertical-align:middle">
            <!-- return Domino resource URL -->
            <xp:link escape="true" text="download..." id="link1">
                  <xp:this.value><![CDATA[#{javascript:
                  "/" + rowData.getUniversalID() + "/$FILE/" +
                  rowData.getColumnValue("FileUpFilename")}]]>
                  </xp:this.value>
            </xp:link>
      </xp:column>
      <xp:column id="column4"
            style="text-align:center; vertical-align:middle">
            <!-- use the same Domino resource URL for the image -->
            <xp:image id="image2" style="height:50px;width:50.0px">
                  <xp:this.url><![CDATA[#{javascript:"/" +
                  rowData.getUniversalID() + "/$FILE/" +
                  rowData.getColumnValue("FileUpFilename")}]]>
                  </xp:this.url>
            </xp:image>
      </xp:column>
</xp:dataTable>

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

Figure 9.28 Example of the File Download control in the Discussion application

That is the Data Table, all done and dusted!

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020