sessionScope.userRoles=context.getUser().getRoles() is on a page template control that provides a consistent framework for all pages on the web site.
sessionScope.userRoles on a control (that’s a facet on the template control) provides a list of user Roles as expected. Code that reads this value also says it’s a java.util.ArrayList object, and “help” refers to the Java documentation on ArrayList.
The Java 1.6 documentation on ArrayList says it supports the contains(obj) method, which returns true if a given object is in the list. Exactly what the doctor ordered.
sessionScope.userRoles.contains(‘[somerole’]) fails:
Exception
sessionScope.userRoles.contains(‘[somerole]’);
Encountered “(”, expected one of [“}”, “.”, “>”, “gt”, “<”, “lt”, “==”, “eq”, “<=”, “le”, “>=”, “ge”, “!=”, “ne”, “[”, “+”, “-”, “*”, “/”, “div”, “%”, “mod”, “and”, “&&”, “or”, “||”, “?”]
Encountered “(” at line 1, column 34. Was expecting one of: “}” … “.” … “>” … “gt” … “<” … “lt” … “==” … “eq” … “<=” … “le” … “>=” … “ge” … “!=” … “ne” … “[” … “+” … “-” … “*” … “/” … “div” … “%” … “mod” … “and” … “&&” … “or” … “||” … “?” …
The runtime is clearly looking for an operator or a JS expression close here, and a method invocation is not allowed. Do I have to manually wade through this list and check each and every element, when there’s method already there to do what I want?
- Searching the forum for “userRoles”, or “user AND roles”, or “check AND Role”, gives up no information on this, or how one might check role membership on an Xpage. “Help” also doesn’t have much of anything on roles in XPages or JavaScript, at least not using the non-configurable index settings. The “script editor” has a very nice object/method browser that has nothing for context-sensitivity; if one finds a likely looking item in the browser, selects it, and presses “F1”, it calls up “script editor help” by adding the uselessly squashed panel to the right. No response at all would significantly more desirable.