auto-generation of repeated elements part 2 of a series of xforms auto generation date: 1/25/2008...

21
Auto-generation of Repeated Elements Part 2 of a series of XForms auto generation Date: 1/25/2008 Dan McCreary President Dan McCreary & Associates [email protected] m (952) 931-9198 M D Metadata Solutions

Upload: roderick-bennett

Post on 04-Jan-2016

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 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

Auto-generation of Repeated Elements

Part 2 of a series of XForms auto generationDate: 1/25/2008

Dan McCrearyPresidentDan McCreary & [email protected](952) 931-9198

M

D

Metadata Solutions

Page 2: 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

Copyright 2008 Dan McCreary & Associates 2

M

D

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

Page 3: 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

Copyright 2008 Dan McCreary & Associates 3

M

D

Conditional Display of Delete

Note: No Delete Button(you can not delete the last

item in a list)

But you candelete the first item

Disable add if we exceed maxOccurs

Page 4: 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

Copyright 2008 Dan McCreary & Associates 4

M

D

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

refnodeset

Page 5: 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

Copyright 2008 Dan McCreary & Associates 5

M

D

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”

Page 6: 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

Copyright 2008 Dan McCreary & Associates 6

M

D

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

<xs:element name="Phone" maxOccurs="unbounded">

Page 7: 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

Copyright 2008 Dan McCreary & Associates 7

M

D

XML Instance

<PersonPhones> <Phone> <PhoneDescriptionText>Home</PhoneDescriptionText> <PhoneNumber>123-456-7890</PhoneNumber> </Phone> <Phone> <PhoneDescriptionText>Work</PhoneDescriptionText> <PhoneNumber>123-456-7891</PhoneNumber> </Phone> <Phone> <PhoneDescriptionText>Moble-1</PhoneDescriptionText> <PhoneNumber>123-456-7892</PhoneNumber> </Phone> <Phone> <PhoneDescriptionText>Moble-2</PhoneDescriptionText> <PhoneNumber>123-456-7893</PhoneNumber> </Phone> <Phone> <PhoneDescriptionText>Cabin</PhoneDescriptionText> <PhoneNumber>123-456-7894</PhoneNumber> </Phone></PersonPhones>

Page 8: 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

Copyright 2008 Dan McCreary & Associates 8

M

D

XForms Repeat

• XPath Query:– /PersonPhones/Phone

<xf:repeat nodeset="/PersonPhones/Phone"> <xf:input ref="PhoneDescriptionText" class="PhoneDescriptionText"/> <xf:input ref="PhoneNumber" class="PhoneNumber"/></xf:repeat>

/* adjust the widths of the text values */.PhoneDescriptionText .xf-value {width: 14ex;}.PhoneNumber .xf-value {width: 24ex;}

Page 9: 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

Copyright 2008 Dan McCreary & Associates 9

M

D

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

DeleteDelete

BindBind

ViewViewModel

Form Body

AddAdd

Page 10: 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

Copyright 2008 Dan McCreary & Associates 10

M

D

Conditional Views In the Model

<!-- views are areas of the screen that are conditionally displayed --> <xf:instance xmlns="" id="views"> <data> <Phone-delete-trigger/> <Phone-add-trigger/> </data> </xf:instance>

We will bind a visibility rule to this element in the model.

Page 11: 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

Copyright 2008 Dan McCreary & Associates 11

M

D

Binding Delete Trigger

<!-- only display the delete trigger if we have a second phone number in the instance --> <xf:bind id=“Phone-delete-trigger" nodeset="instance('views')/phone-delete-trigger" relevant="instance(‘save-data’')/Phone[2]"/>

<!-- bind="phone-delete-trigger" --><xf:trigger bind="Phone-delete-trigger"> <xf:label>Delete</xf:label> <!-- this deletes the currently selected phone number --> <xf:delete nodeset="instance('phones')/Phone[index('phone-number-repeat')]" ev:event="DOMActivate"/></xf:trigger>

The binding rule in the model

The delete button inside the repeat loop

Page 12: 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

Copyright 2008 Dan McCreary & Associates 12

M

D

Disable “Add” at Five

Add button view is relevant whencount is less than five

Disable add button whencount is five

This prevents the user from adding moreitems then the XML Schema permits

Page 13: 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

Copyright 2008 Dan McCreary & Associates 13

M

D

Disable the Add Trigger

<xf:bind id=“Phone-add-trigger" nodeset="instance('views')/Phone-add-trigger" relevant="count(instance(‘save-data')/Phone) &lt; 5"/>

<xs:element name="Phone" minOccurs="2" maxOccurs="5">

From the XML Schema we want to build a user interfacethat will only generate between two and five rows of data.

The bind rule will only show user interfaces contorls where thereare less then five phone numbers.

XML Schema Defintion:

Page 14: 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

Copyright 2008 Dan McCreary & Associates 14

M

D

The Body Generated Code<body> <xf:label class="group-label">Phone Numbers</xf:label> <xf:repeat id="Phone-repeat" nodeset="/PersonPhones/Phone"> <xf:input ref="PhoneDescriptionText" class="PhoneDescriptionText" id="PhoneDescriptionText"/> <xf:input ref="PhoneNumber" class="PhoneNumber"/>

<xf:trigger bind="Phone-delete-trigger"> <xf:label>Delete</xf:label> <!-- this deletes the currently selected phone number --> <xf:delete nodeset="instance('save-data')/Phone[index('Phone-repeat')]" ev:event="DOMActivate"/> </xf:trigger>

</xf:repeat> <xf:trigger bind="Phone-add-trigger"> <xf:label>Add</xf:label> <xf:action ev:event="DOMActivate"> <xf:insert nodeset="instance('save-data')/Phone" at="last()" position="after"/> <!-- this initialized the values of the phone number to null. Can also use an origin attribute. --> <xf:setvalue ref="instance('save-data')/Phone[index('Phone-repeat')]/PhoneDescriptionText" value=""/> <xf:setvalue ref="instance('save-data')/Phone[index('Phone-repeat')]/PhoneNumber" value=""/> <!-- this puts the cursor in the first field of the new row we just added --> <xf:setfocus control="PhoneDescriptionText"/> </xf:action> </xf:trigger></body>

Page 15: 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

Copyright 2008 Dan McCreary & Associates 15

M

D

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

Page 16: 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

Copyright 2008 Dan McCreary & Associates 16

M

D

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

Page 17: 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

Copyright 2008 Dan McCreary & Associates 17

M

D

s2f Functions

• Model:– s2i:conditional-views($schema)– s2i:view-bind-rules($schema)

• Body– s2i:xforms-body($schema, $schema, ‘’)

Page 18: 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

Copyright 2008 Dan McCreary & Associates 18

M

D

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

Page 19: 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

Copyright 2008 Dan McCreary & Associates 19

M

D

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

<xf:item> <xf:label>{$label}</xf:label> <xf:value>{$value}</xf:value></item>

• Can be easily replaces by a metadata registry-backed XQuery function that includes screen labels

Page 20: 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

Copyright 2008 Dan McCreary & Associates 20

M

D

Sample XForms Driver<head>

<xf:model> <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)} <xf:submission id="save" method="post" action="save-new.xq" instance="save-data"/></xf:model>

</head><body>

{style:header()} {style:breadcrumb()} {s2f:xforms-body($schema, $schema, '')} <xf:submit submission="save"> <xf:label>Save</xf:label> </xf:submit>

{style:footer()}</body>

Page 21: 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

Copyright 2008 Dan McCreary & Associates 21

M

D

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, PresidentDan McCreary & Associates

Metadata Strategy [email protected]

(952) 931-9198