Viu algo para melhorar? Proponha uma alteração.
Em XForms · página 61 de 137
Motivation
You have a large model and you want to incrementally load different portions of the model when they are needed. This is frequently done when you have a multi-part form and each tab needs additional data. Loading only the data for the initial tab keeps your form load times fast and avoids unnecessarily locking shared data resources.
Method
We will create a model with three separate instances, one for a list of people, one for a list of places and one for a list of things. The people will automatically be loaded into the form when the form loads. We will create triggers that will incrementally load the other portions of the model when they are needed. Each trigger
will use a submission event that does a separate HTTP get to incrementally load data into a separate instance in the model.
Here is the empty place-holder instance in the model for the places and the submission to get the places data.
id="places">
id="get-places" method="get" action="places.xml"
replace="instance" instance="places"/>
Here is the trigger (button) that gets the new model.
submission="get-places">
Load Places
Screen Image
The following are the before and after screen images. The before screen image is when the form initially loads. The after image is after the user has pressed the two triggers for loading the places and things.
Before Model Fully Loaded (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)
After Model Fully Loaded (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)
The above example is designed to be very easy to see how data is loaded when an event is triggered. In practice each tab in a multi-tab
form may have some data that is only needed if the users click on that tab. This is a perfect use of dynamic model loading. The example below illustrates this best-practice.
Note event log does not reload model data (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0)
Load XForms Application
Example with triggers that manually load incremental data:
Load XForms Application
Example with tab-selection events that incrementally load data
Load XForms Application
Note that in this example the event log shows that the data is only loaded once regardless of how many times the tab is selected.
Avoiding Reloads
The following is an example of how to use conditional actions to check if a instance in the model
already has its data loaded into the form:
id="places-case">
ev:event="xforms-select" if="not(instance('places')/place)">
submission="get-places"/>
Places
The if attribute of the xf:action checks to see if there is at least one place in the places instance. If there is not at least one "place" the submission event is fired.
Sample Code
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events">
Incremental Model Loading
type="text/css">body {font-family: Helvetica, Arial, sans-serif;
id="people" src="people.xml">
id="places">
id="get-places" method="get" action="places.xml"
replace="instance" instance="places"/>
id="things">
id="get-things" method="get" action="things.xml"
instance="things" replace="instance"/>
Incremental Model Loading
Not all parts of the model need to be loaded into a form when it is first loaded. For
large models, different sections can be loaded as they are needed.
People
ref="instance('people')">
nodeset="person">
ref="name"/>
Places
ref="instance('places')">
nodeset="place">
ref="name"/>
submission="get-places">
Load Places
Things
ref="instance('things')">
nodeset="item">
ref="name"/>
submission="get-things">
Load Things
XML Instance Samples
[people.xml]
[places.xml]
[things.xml]
Where this page came from
This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.
Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.
Nestas publicaçõesXForms
Licença: CC BY-SA 4.0 · Adaptado de en.wikibooks.org
1
0
0
0

Comentários






