...
User attributes are custom values that are associated with a user, generally being read from a database table but can be provided in other ways, and these . These values can be referenced in a client configuration to provide the value for any attribute in the configuration.
For example, if a user, or group of users, should be presented with an initial table of contents Table of Contents (ToC) for the map when they start a Weave client then the “toc” tag in that client configuration can be setup in such a way that the value for the name of the toc model to use can be provided by a user attribute.
...
In the above example if the value for the “toc” attribute for the current user is “main” then the above would be the equivalent of:
Code Block |
---|
|
<toc ref="main"/> |
...
If you can’t, or don’t to want to, set a value for an attribute for all users you can specify a default value for the attribute directly in the config, for . For example, if we wanted to use “main” as the default toc model to use , but have some users use something different, then you would use the following format:
Code Block |
---|
|
<toc ref="${user.toc|main}"/> |
so if If one user had the value “custom” for the toc attribute, it would be equivalent to:
Code Block |
---|
|
<toc ref="custom"/> |
and if If another user did not have a toc attribute at all it would be equivalent to:
Code Block |
---|
|
<toc ref="main"/> |
Converting Values
Weave will try and guess the type of the value, either the attribute value or the default value, and convert the value to that type , using the same rules that the config file reader uses when initially reading the values from the XML files. As such, and as such there may be times when the conversion is incorrect, for . For example, if the value of the attribute is “1234”, Weave will convert that to the number 1234, for example. So:
Code Block |
---|
|
<tag value="${user.number}"/> |
would result in the following object:
Code Block |
---|
|
{tag: {value: 1234}} |
If the value is supposed to be a string and not a number, then you can override this by appending a colon followed by a format, for . For example, if the value of the user.number
attribute is 1234 but you need tag.value
to be a string you can explicitly specify the type of the value like. So:
Code Block |
---|
|
<tag value="${user.number:string}"/> |
would result in the following object:
Code Block |
---|
|
{tag: {value: "1234"}} |
And this This is the same but providing provides a default in case the user does not have a number
attribute:
Code Block |
---|
|
<tag value="${user.number|1234:string}"/> |
Note that type conversion only applies when the entire value is replaced by the user attribute, if . If the user attribute replacement is only part of the final value then it will always be treated as a string and the format will be ignored, for . For example:
Code Block |
---|
|
<item text="Number: ${user.number:float}"/> |
would beresult in the following object:
Code Block |
---|
|
{item: {text: "Number: 1234"}} |
...