Use TreeSet to get keyword values, avoiding duplicates and sorting


Static method in Utils library (it's advisable to use a more specific name that just Utils, to avoid confusion of Class names, which is why Extension Library has ExtLibUtils) has :
public static String[] getKeyObj(String key) {
  Database currDb = ExtLibUtil.getCurrentDatabase();
  View vwUser = currDb.getView("Keywords");
  ViewEntry ent = vwUser.getEntryByKey(key, true);
  Vector<String> users = (Vector<String>) ent.getColumnValues().get(1);
  return new TreeSet(users).toArray();
}

Code from managed bean - "Utils" will need to match the name you've given to your static library
public String[] getDepartments() {
  return Utils.getKeyObj("Departments");
}

Code from XPage - the ValueBinding "myBean.departments" will look for a method "getDepartments" in myBean
<xp:comboBox id="comboBox1">
	<xp:selectItems>
			<xp:this.value><![CDATA[${myBean.departments}]]></xp:this.value>
	</xp:selectItems>
</xp:comboBox>
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...