Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

From Weave 2.6.5 onwards it’s possible to customise a client based on attributes associated with the user.

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 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 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.

<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

<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 to use but have some users use something different then you would use the following format

<toc ref="${user.toc|main}"/>

so if one user had the value “custom” for the toc attribute it would be equivalent to

<toc ref="custom"/>

and if another user did not have a toc attribute at all it would be equivalent to

<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, and 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, for example

<tag value="${user.number}"/>

would result in the following object

{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 like:

<tag value="${user.number:string}"/>

would result in the following object

{tag: {value: "1234"}}

And this is the same but providing a default in case the user does not have a number attribute

<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

<item text="Number: ${user.number:float}"/>

would be

{item: {text: "Number: 1234"}}

  • No labels