The Mobilengine form language features naming scopes with nesting. A scope is where an element in the form is accessible for data-binding. The outermost or global scope is accessible for data-binding anywhere in the form.
Global scope is defined implicitly by the framework and holds the root of the form
with the id
of the form, the built-in sysp
scope for all the
system parameters,
and the reference tables.
You can declare any number of further scopes in the form by specifying an
id
field on a
control. Controls that have an id
begin their own scopes, which are nested in
the scope of their closest ancestor with an
identifier.
Figure 217. In references from outside the parent scope, a property's qualified name includes both the parent and the nested scope
If a named control has no ancestor with an identifier, its scope will be nested in the form root.
<formid="scopes"
...> ... <textview label="The text input from inside the popup:"text='{scopes.boxBar.text}'
/> <popup title="Reference to a named control from an aunt"> <textboxid="boxBar"
label="Type something"/> <textview label="Your text input appears here"text='{boxBar.text}'
/> </popup> ... </form>
Generally, control properties and variables are accessible for data-binding only if they have an id
field declared. The single exception is that a control's own properties are accessible for
data-binding in other properties of the
control.
Figure 219. The label
property of the textview
is accessible
inside it even though it doesn't have an id
field
Properties and variables are accessible within their own and all their nested scopes by using their unprefixed names. From within external scopes, you need to use qualified names to access them.
Identifiers must be unique within their scope.
However, in a nested scope, you can have controls or variables with identifiers that shadow an identifier in the parent scope.
... <popup id='knights' title='Ni no more'> <textboxid='ni'
width="30 em" text='We are no longer the knights who say ni.'/> </popup> <popup id='newKnights' title='Ekki-ekki-ekki-pitang-zoom-boing'> <textboxid='ni'
width="40 em" text='We are the knights who say ekki-ekki-ekki-pitang-zoom-boing.'/> </popup>
If you declare an element in a nested scope with an identifier that already exists in a parent scope, the same-named identifier will shadow the parent's one inside the nested scope, that is, refer to the newly-created element.
You have to use qualified names to access the shadowed properties inside the nested scope where the shadowing identifier is declared, to make sure that you don't return the value of the masking property instead of the shadowed one.
... <chapter id="parent" title="Parent scope"> <textboxid="tbFoo"
text="parent-value"/> <chapter id="nested" title="Nested scope"> <textboxid="tbFoo"
text="nested-value"/> <textview label="tbFoo.text" text='{tbFoo.text}
'/> <textview label="parent.tbFoo.text" text='{parent.tbFoo.text}
'/> </chapter> <textview label="tbFoo.text" text='{tbFoo.text}
'/> </chapter> ...
Figure 221. Reference to the same identifier returns different results depending on the current scope
The names of reference table names may not be shadowed by any identifier in a form.