...
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 particular 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.
Code Block |
---|
|
<toc ref="${user.toc}"/> |
Note this example assumes that a user attribute called “toc” has been associated with all users.
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"/> |
Default Values
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 example, if we wanted to use “main” as the default toc model, but have some users use something different, then you would use the following format:
Code Block |
---|
|
<toc ref="${user.toc|main}"/> |
If one user had the value “custom” for the toc attribute, it would be equivalent to:
Code Block |
---|
|
<toc ref="custom"/> |
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, there may be times when the conversion is incorrect. For example, if the value of the attribute is “1234”, Weave will convert that to the number 1234. 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 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. So:
Code Block |
---|
|
<tag value="${user.number:string}"/> |
would result in the following object:
Code Block |
---|
|
{tag: {value: "1234"}} |
This is the same but 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 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 example:
Code Block |
---|
|
<item text="Number: ${user.number:float}"/> |
would result in the following object:
Code Block |
---|
|
{item: {text: "Number: 1234"}} |