Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • IBM Forms wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category All IBM Forms 4.0 documentation IBM Forms Server 4.0 API documentation Custom Search Scope...
Search
Community Articles > Samples > Change Tracking Sample Form
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

Ryan Nordman
Contribution Summary:
  • Articles authored: 25
  • Articles edited: 25
  • Comments Posted: 0

Recent articles by this author

Dataset Browser Modal Dialog Sample WFS4

This sample demonstrates a technique for showing a large list in an HTML modal dialog using dojo, and pushing selections from the list back into the form using the Javascript API.

Dynamic Multiple Error Messages Using XForms Bind and Alert

This article outlines a technique for developing forms with multiple error messages on a single field. In cases where you would like to present the user with several different error messages depending on the type of validation error being made, this technique uses a minimal amount of code and ...

Multilingual Forms Applications

This article includes a sample form with servlet and will discuss approaches and techniques to develop multilingual forms applications, through two approaches: creating a separate form document for each language, or creating a single form which dynamically changes its labels for each ...

The Expressive Power of XForms Binds and XPath

The goal of this sample is to illustrate some of the expressive power of XForms binds and how an XPath nodeset in a bind is used at runtime to evaluate the result of a bind. In this example the goal is to count the number of occurrences of specific text entries in a homogeneous set of XML ...

Basic XForms Tables Tutorial Part 2: Add/Remove Buttons

This article is meant as a sequel to a previous article on basic XForms Tables. You can read the first article http:www10.lotus.comlddlfwiki.nsfdx04292009040220PMRNOV22.htmhere. The first article outlines how to build a very simple Lotus Forms XForms table with two fields. We will pick ...

Community articleChange Tracking Sample Form

Added by Ryan Nordman | Edited by IBM contributor Jane Rizhanovsky on July 7, 2009 | Version 6
  • Edit
  • More Actions Show Menu▼
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: xfdl, compute, samples
This WebForm Server friendly form demonstrates one way you can track what changes a user makes to a form. This approach is WebForm Server friendly because it does not use any Viewer-only event model options such as focused and focuseditem. Instead, the form records when the user changes the value of a field, or triggers a button to add or delete rows in a table. These events are captured using a combination of XForms actions and XFDL computes found in the form's input items, and are stored in a separate changeTrackingData instance in the XForms model. The changes captured in the changeTrackingData instance can be viewed via a table found on page 3 of the form.

In order for this change tracking mechanism to be re-purposed in another form you must add the following pieces to the new form :

1. The changeTrackingData instance must be copied to the default XForms model.

changeTrackingData XForms Data Instance
<xforms:instance id="changeTrackingData" xmlns="">
<data>
<changeCount>0</changeCount>
<changeList>
</changeList>
<templateChange>
<change>
<timeStamp></timeStamp>
<type></type>
<id></id>
<xpathRef></xpathRef>
<data></data>
</change>
</templateChange>
</data>
</xforms:instance>

The data being tracked in this sample are the type of change (data, table_add, or table_delete), the id of the xforms control used to make the change (if available), the full xpath reference of the node being changed in the model, the new contents of the node (or info about what row was added or deleted), and when the change occurred. But you can customize this data as you see fit.

2. A generic change tracking compute must be added to each field that wraps an xforms:textarea that has a fully qualified xpath reference. If you want to use this compute in other types of xforms controls (xforms:select1, xforms:input, etc...), the compute must be updated appropriately.

Generic onChange Compute For xforms:textarea
<custom:onChange xfdl:compute="(toggle(value) == '1') &#xA;
? set('instance(&quot;changeTrackingData&quot;)/templateChange/change/xpathRef', getAttr('xforms:textarea', 'option', 'xforms:ref'), '', 'xforms') &#xA;
+. ((getAttr('xforms:textarea', 'option', 'xforms:id') != '') &#xA;
? set('instance(&quot;changeTrackingData&quot;)/templateChange/change/id', getAttr('xforms:textarea', 'option', 'xforms:id'), '', 'xforms') &#xA;
: '' &#xA;
) &#xA;
+. set('instance(&quot;changeTrackingData&quot;)/templateChange/change/data', value, '', 'xforms') &#xA;
+. set('instance(&quot;changeTrackingData&quot;)/changeCount', get('instance(&quot;changeTrackingData&quot;)/changeCount', '', 'xforms') + '1', '' ,'xforms') &#xA;
: ''"></custom:onChange>

3. A "for tables" change tracking compute must be added to items using relative xpath references (such as items in tables) AND then customized for your table or other type of pane. Customization involves replacing the "instance("formData")/residents/persons/person" portion of the xpath reference being built by this compute with the nodeset of your xforms:repeat or xforms:group. Once updated, this compute can then be copied into every field in this table.

A "For Tables" onChange Compute For xforms:textarea
<custom:onChange xfdl:compute="(toggle(value) == '1') &#xA;
? set('instance(&quot;changeTrackingData&quot;)/templateChange/change/xpathRef', '*instance(&quot;formData&quot;)/residents/persons/person*[' +. xforms.getPosInSet() +. ']/' +. getAttr('xforms:textarea', 'option', 'xforms:ref'), '', 'xforms') &#xA;
+. ((getAttr('xforms:textarea', 'option', 'xforms:id') != '') &#xA;
? set('instance(&quot;changeTrackingData&quot;)/templateChange/change/id', getAttr('xforms:textarea', 'option', 'xforms:id'), '', 'xforms') &#xA;
: '' &#xA;
) &#xA;
+. set('instance(&quot;changeTrackingData&quot;)/templateChange/change/data', value, '', 'xforms') &#xA;
+. set('instance(&quot;changeTrackingData&quot;)/changeCount', get('instance(&quot;changeTrackingData&quot;)/changeCount', '', 'xforms') + '1', '' ,'xforms') &#xA;
: ''"></custom:onChange>

4. Add xforms:actions to any buttons (wrapping xforms:trigger) that you want to know are clicked. For example, a delete button for a table might have the following action.

A xforms:action To Add To Buttons
<xforms:action ev:event="DOMActivate">
<xforms:setvalue ref="instance('changeTrackingData')/templateChange/change/type">table_delete</xforms:setvalue>
<xforms:setvalue ref="instance('changeTrackingData')/templateChange/change/id">PERSON_REPEAT</xforms:setvalue>
<xforms:setvalue ref="instance('changeTrackingData')/templateChange/change/data" value="index('PERSON_REPEAT')"></xforms:setvalue>
<xforms:delete at="index('PERSON_REPEAT')" nodeset="instance('formData')/residents/persons/person"></xforms:delete>
<xforms:setfocus control="PERSON_REPEAT"></xforms:setfocus>
<xforms:setvalue ref="instance('changeTrackingData')/changeCount" value="instance('changeTrackingData')/changeCount + 1"></xforms:setvalue>
</xforms:action>

5. The invisible CHANGECOUNT1 field must be copied to every page of the form containing "change tracking" code. You will notice the previous computes and actions that you added to input items add information within "instance('changeTrackingData')/templateChange/change" and then increment the "instance('changeTrackingData')/changeCount". This invisible field watches the changeCount and when it changes is responsible for committing the latest tracking data by copying the templateChange/change node to the the changeList portion of the changeTrackingData instance.

CHANGECOUNT1 Field
<field sid="CHANGECOUNT1">
<xforms:textarea ref="instance('changeTrackingData')/changeCount">
<xforms:label></xforms:label>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="instance('changeTrackingData')/templateChange/change/timeStamp" value="now()"></xforms:setvalue>
<xforms:setvalue if="instance('changeTrackingData')/templateChange/change/type = ''" ref="instance('changeTrackingData')/templateChange/change/type">data</xforms:setvalue>
<xforms:insert at="last()" context="instance('changeTrackingData')/changeList" nodeset="instance('changeTrackingData')/changeList/change" origin="instance('changeTrackingData')/templateChange/change" position="after"></xforms:insert>
<xforms:setvalue ref="instance('changeTrackingData')/templateChange/change/type"></xforms:setvalue>
<xforms:setvalue ref="instance('changeTrackingData')/templateChange/change/xpathRef"></xforms:setvalue>
<xforms:setvalue ref="instance('changeTrackingData')/templateChange/change/id"></xforms:setvalue>
</xforms:action>
</xforms:textarea>
<itemlocation>
<x>486</x>
<y>45</y>
<width>111</width>
</itemlocation>
<label>Change Count</label>
</field>

Notes

Hopefully this invisible field will spark some creative ideas of your own. Not only is it an example of how you can modularize common code by placing it in a single field that other form events can trigger, but it also demonstrates how to bridge the gap between XFDL and XForms. Sometimes you need a feature only available in XForms (like inserting a row in a repeating section of your instance) but you are responding to a form event within an XFDL compute. This approach allows you to get the best of both worlds.

This samples shows how you can use the xforms.getAttr function from within an XFDL compute in order to get information about the XForms control that the current XFDL item wraps. If you look at the onChange compute you can see how it can be used to get the ref and id attributes of an xforms:textarea.

  • Edit
  • More Actions Show Menu▼


expanded Attachments (1)
collapsed Attachments (1)
Edit the article to add or modify attachments.
File TypeSizeFile NameCreated On
application/octet-stream 45 KB changeTrackingForWFS.xfdl 4/13/09 6:58 PM
expanded Versions (6)
collapsed Versions (6)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (6)Jul 7, 2009 5:13:39 PMJane Rizhanovsky  IBM contributor
5Apr 15, 2009 1:49:34 PMDeanna Drschiwiski  IBM contributor
4Apr 14, 2009 4:35:25 PMDeanna Drschiwiski  IBM contributor
3Apr 13, 2009 7:04:40 PMRyan Nordman  IBM contributor
2Apr 13, 2009 7:02:19 PMRyan Nordman  IBM contributor
1Apr 13, 2009 6:55:52 PMRyan Nordman  IBM contributor
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use