Tommy Valand in his
blog post pointed to a
StackOverflow question to add <optgroup> in combo box in JSF. Using hints from there I was able to devise a way to get <optgroup> in combo box for XPages. Below is the code snippet for the combo box.
<xp:comboBox id="comboBox1">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var options:java.util.ArrayList = new java.util.ArrayList();
var group1:javax.faces.model.SelectItemGroup = new javax.faces.model.SelectItemGroup("Group 1");
var group1Items = new Array();
group1Items[0] = new javax.faces.model.SelectItem("Group 1 Value 1", "Group 1 Label 1");
group1Items[1] = new javax.faces.model.SelectItem("Group 1 Value 2", "Group 1 Label 2");
group1Items[2] = new javax.faces.model.SelectItem("Group 1 Value 3", "Group 1 Label 3");
group1.setSelectItems(group1Items);
var group2:javax.faces.model.SelectItemGroup = new javax.faces.model.SelectItemGroup("Group 2");
var group2Items = new Array();
group2Items[0] = new javax.faces.model.SelectItem("Group 2 Value 1", "Group 2 Label 1");
group2Items[1] = new javax.faces.model.SelectItem("Group 2 Value 2", "Group 2 Label 2");
group2Items[2] = new javax.faces.model.SelectItem("Group 2 Value 3", "Group 2 Label 3");
group2.setSelectItems(group2Items);
options.add(group1);
options.add(group2);
return options;}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
Thanks for this tip! Just what I was looking for. It works very well.
ReplyDelete