问题
I am supporting my companies oldest and first XPages application. The app does not use java for anything and uses SSJS for everything. I do not wish to start using java beans for just this one task.
This question deals with the java way to do the same thing I need: Populating selectItems of the combobox (label, value) using a managed bean (although this I know this is the better way, I am trying to stick to the pattern established already)
The app loads all keywords into applicationScope and then uses them when needed. I am trying to load display values and return the associated value when stored. This is similar to how traditional Notes behaved for years.
I changed the applicationScope values to store the values after a pipe (|) but I haven't figured out how to use the value using SSJS. I am starting to doubt that it is even possible.
I tried using the core combobox control instead of the Dojo combo box to generate the code I would need. It appears like you cannot use separate "formula items" for label and value. Has anyone out there come up with a solution for this one, short of using a java collection.
回答1:
You can use the Java solution in SSJS. You just need var
instead of the initial class name and the full class names in the new
references, so java.util.ArrayList instead of ArrayList and javax.faces.model.SelectItem instead of SelectItem. See here http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/xpages-best-practice-computed-selection-lists?opendocument&comments.
So the code in the StackOverflow question you linked to converted to SSJS should be:
var options = new java.util.ArrayList();
var option = new javax.faces.model.SelectItem();
option.setLabel("Here's a label");
option.setValue("Here's a value");
options.add(option);
return options;
回答2:
You can use Java class javax.faces.model.SelectItem
in SSJS to populate the selectItems:
<xp:comboBox id="comboBox1">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:
var item1 = new javax.faces.model.SelectItem("Value1", "Label1");
var item2 = new javax.faces.model.SelectItem("Value2", "Label2");
[item1, item2]
}]]></xp:this.value>
</xp:selectItems>
...
</xp:comboBox>
回答3:
Maybe I am missing your question, since my response is fairly simple, but to compute the labels and values using JavaScript, create a JavaScript array of strings where each string has the format of "Label|Value" (the vertical bar is the separator as in a Domino field).
Howard
来源:https://stackoverflow.com/questions/27361013/use-ssjs-only-to-populate-dojo-combo-box-and-include-separate-itemlabel-and-item