xPages Example: Generating Dynamic Editable Fields from a Document Collection Author: John Mackey Groupware Solutions Inc. John.Mackey@Groupwareinc.com Blog: http://www.jmackey.net
Overview This example extends a previous example: “Updating data from multiple forms on a single xPage”. You can download the previous example from here: http://www.jmackey.net/groupwareinc/johnblog/johnblog.nsf/d6plinks/GROC-7FFLYJ This new example will walk you through how to use a Repeat control to generate fields dynamically for a document collection The Repeat control repeats a Panel control which binds to each Document in the collection The Panel control contains 3 editable fields bound to fields on each document A simple action “Save Datasources” handles the updates for all bound datasources
Sample Screen shot of Orders page Bound to Order Form Bound to Multiple Response Documents * Fields are generated Dynamically on page load for each response document Bound to Customer Form
First Step: Create/Modify the Notes Forms Create a new form named “OrderDetails”. Make it a Response document Here is the layout for the form: Modify the “Order” form from the previous example Add a new field named “OrderNumber” Delete the fields: ItemNumber,Price,Quantity Here is the layout for the form:
Modify the view Modify the Orders View Change the selection formula to include the new “OrderDetails” form Check off the property “Show response documents in hierarchy” Add a column for “OrderNumber”
Modify the Orders xPage Add new text for “Order Details” section Add a Button labeled “Add New Line”
Modify the Orders xPage When the button is clicked we want to add a new response document and then reload the page. Note: the reloading of a page will be easier with Beta 2 by using context.reloadPage() The onclick() event for the button should be the following:
Modify the Orders xPage Drag a Table control and then drag a Repeat control to the table Set the Options for the repeat control as below:
Modify the Orders xPage For the Iteration formula for the repeat control, enter the following:
Modify the Orders xPage Drag a Panel control to the Repeat Control On the Data tab for the Panel, create a new datasource named “OrderDetails” Set the form to “OrderDetails” Set the action to “Edit document”
Modify the Orders xPage Set the “Document ID” to computed The document id will be the “Collection name” variable for the Repeat control. So as the Repeat control iterates through the response documents it will pass the NoteID in the variable “docid” to each Panel
Modify the Orders xPage We need to set a property on the Panel control so that the Panel ignores any request parameters for the Orders page. For example: the page receives and uses parameters such as “editDocument” and “documentID”. For this use case we calculate the documentID for the Panel and so we want to ignore the page parameters. Click on the All Properties on the Properties tab for the “CustomerData” Panel Expand Data and set “ignoreRequestParams” to true
Modify the Orders xPage Add a 3 column by 1 row table to the Panel Add a ComboBox control to the first column Bind it to the OrderDetails - ItemNumber field
Modify the Orders xPage On the ItemNumber Values tab, Add some values: Add 2 EditBox controls and bind them to Price and Quantity
Recreate Orders View Control Open up the “ViewCustomers” xPage Click on the Orders tab Delete the view and drag a new view control to the tab (I just find this easier then adding new columns) Select “vOrders” view for the source Select “Indent Responses” for the CustomerName column properties tab On the “Order Num” column properties tab, select “show values in this column as links”
Here’s a screen shot of the updated view
Test the Application Create some Orders and click “Add New Line” button numerous times You can also still update the Customer information from the Order This simple action handles all the updates:
Questions?? Contact me if you have any questions John.Mackey@Groupwareinc.com or comment on my blog: http://www.jmackey.net The Domino 8.5 discussion forum is: http://www-10.lotus.com/ldd/nd85forum.nsf