Presentation is loading. Please wait.

Presentation is loading. Please wait.

Auto-generation of Repeated Elements Part 2 of a series of XForms auto generation Date: 1/25/2008 Dan McCreary President Dan McCreary & Associates

Similar presentations


Presentation on theme: "Auto-generation of Repeated Elements Part 2 of a series of XForms auto generation Date: 1/25/2008 Dan McCreary President Dan McCreary & Associates"— Presentation transcript:

1 Auto-generation of Repeated Elements Part 2 of a series of XForms auto generation Date: 1/25/2008 Dan McCreary President Dan McCreary & Associates dan@danmccreary.com (952) 931-9198 M D Metadata Solutions

2 M D Copyright 2008 Dan McCreary & Associates2 Agenda/Objective Why repetition is hard –Dynamic controls –Conditional display of delete trigger for last item in a set –Conditional display of add button for maxOccurs The Tools –Group/ref and Repeat/nodeset Model Supporting Structures –conditional views –bindings Design Patterns –Inline Table Editing –Summary Line/Inspectors

3 M D Copyright 2008 Dan McCreary & Associates3 Conditional Display of Delete Note: No Delete Button (you can not delete the last item in a list) But you can delete the first item Disable add if we exceed maxOccurs

4 M D Copyright 2008 Dan McCreary & Associates4 Ref vs Nodeset Ref points to a single node and is used by group and other controls to set the context Nodeset points to a sequence of nodes in is used by the repeat element ref nodeset

5 M D Copyright 2008 Dan McCreary & Associates5 Schema Derived Presentation Rules XML Schemas describe the cardinality restrictions using two attributes of and element –minOccurs –maxOccurs Never delete the last remaining item in a nodeset. This is needed for the form. You do not need to disable the Add button if the maxOccurs=“unbounded”

6 M D Copyright 2008 Dan McCreary & Associates6 Sample XML Schema A person has one to many phone numbers Note that in this example you MUST have at lease one phone number but it might be blank This is required by XForms so that the views have some data to map to Null elements sometimes must be added before an instance is loaded into a form

7 M D Copyright 2008 Dan McCreary & Associates7 XML Instance Home 123-456-7890 Work 123-456-7891 Moble-1 123-456-7892 Moble-2 123-456-7893 Cabin 123-456-7894

8 M D Copyright 2008 Dan McCreary & Associates8 XForms Repeat XPath Query: –/PersonPhones/Phone /* adjust the widths of the text values */.PhoneDescriptionText.xf-value {width: 14ex;}.PhoneNumber.xf-value {width: 24ex;}

9 M D Copyright 2008 Dan McCreary & Associates9 Steps Create a place to put visibility data (the ‘views’ instance) Create visibility rules with bind elements in the model Bind the screen elements to the rules using a bind ID Link the three components together Delete Bind View Model Form Body Add

10 M D Copyright 2008 Dan McCreary & Associates10 Conditional Views In the Model We will bind a visibility rule to this element in the model.

11 M D Copyright 2008 Dan McCreary & Associates11 Binding Delete Trigger <xf:bind id=“Phone-delete-trigger" nodeset="instance('views')/phone-delete-trigger" relevant="instance(‘save-data’')/Phone[2]"/> Delete <xf:delete nodeset="instance('phones')/Phone[index('phone-number-repeat')]" ev:event="DOMActivate"/> The binding rule in the model The delete button inside the repeat loop

12 M D Copyright 2008 Dan McCreary & Associates12 Disable “Add” at Five Add button view is relevant when count is less than five Disable add button when count is five This prevents the user from adding more items then the XML Schema permits

13 M D Copyright 2008 Dan McCreary & Associates13 Disable the Add Trigger <xf:bind id=“Phone-add-trigger" nodeset="instance('views')/Phone-add-trigger" relevant="count(instance(‘save-data')/Phone) < 5"/> From the XML Schema we want to build a user interface that will only generate between two and five rows of data. The bind rule will only show user interfaces contorls where there are less then five phone numbers. XML Schema Defintion:

14 M D Copyright 2008 Dan McCreary & Associates14 The Body Generated Code Phone Numbers Delete Add

15 M D Copyright 2008 Dan McCreary & Associates15 Model Steps for Auto-generator Find all elements in the entire XML Schema that have repeating structures Create a views instance and for each of the repeating elements, add one element for the delete trigger Create binding rules for each of the instances

16 M D Copyright 2008 Dan McCreary & Associates16 Body Steps for Auto-generator For each repeatable element –Generate a repeat-loop –Place Delete Triggers on Each Line –Add a Add trigger to the end of the repeat

17 M D Copyright 2008 Dan McCreary & Associates17 s2f Functions Model: –s2i:conditional-views($schema) –s2i:view-bind-rules($schema) Body –s2i:xforms-body($schema, $schema, ‘’)

18 M D Copyright 2008 Dan McCreary & Associates18 When We have Repetition We use s2i:repeat($schema, $element) Generates an xf:repeat statement that uses the count of items in the instance to generate user interface elements Works with repeating simple and complex types

19 M D Copyright 2008 Dan McCreary & Associates19 Code Tables s2f:code-tables($schema) Generates an single of code tables instance in the model that holds all the code tables How it works: –for $enumerated-element in $schema for $code in $enumerated-elements {$label} {$value} Can be easily replaces by a metadata registry- backed XQuery function that includes screen labels

20 M D Copyright 2008 Dan McCreary & Associates20 Sample XForms Driver <xf:instance xmlns="" id="save-data" src="/exist/rest/db/xrx/modules/test-input-instances/{$my-form}.xml"/> {s2f:code-tables($schema)} {s2f:conditional-views($schema)} {s2f:required-binds($schema)} {s2f:date-binds($schema)} {s2f:indicator-binds($schema)} {s2f:trigger-visability-bind-rules($schema)} {style:header()} {style:breadcrumb()} {s2f:xforms-body($schema, $schema, '')} Save {style:footer()}

21 M D Copyright 2008 Dan McCreary & Associates21 Thank You! Please contact me for more information: Native XML Databases Metadata Management Metadata Registries Service Oriented Architectures Business Intelligence and Data Warehouse Semantic Web Dan McCreary, President Dan McCreary & Associates Metadata Strategy Development dan@danmccreary.com (952) 931-9198


Download ppt "Auto-generation of Repeated Elements Part 2 of a series of XForms auto generation Date: 1/25/2008 Dan McCreary President Dan McCreary & Associates"

Similar presentations


Ads by Google