/** * Identify the itemset in the backend model, and create a set of SelectChoice objects at the * current question reference based on the data in the model. * * <p>Will modify the itemset binding to contain the relevant choices * * @param itemset The binding for an itemset, where the choices will be populated * @param curQRef A reference to the current question's element, which will be used to determine * the values to be chosen from. */ public void populateDynamicChoices(ItemsetBinding itemset, TreeReference curQRef) { Vector<SelectChoice> choices = new Vector<SelectChoice>(); Vector<TreeReference> matches = itemset.nodesetExpr.evalNodeset( this.getInstance(), new EvaluationContext(exprEvalContext, itemset.contextRef.contextualize(curQRef))); for (int i = 0; i < matches.size(); i++) { TreeReference item = matches.elementAt(i); String label = itemset.labelExpr.evalReadable( this.getInstance(), new EvaluationContext(exprEvalContext, item)); String value = null; TreeElement copyNode = null; if (itemset.copyMode) { copyNode = this.getInstance().resolveReference(itemset.copyRef.contextualize(item)); } if (itemset.valueRef != null) { value = itemset.valueExpr.evalReadable( this.getInstance(), new EvaluationContext(exprEvalContext, item)); } // SelectChoice choice = new SelectChoice(labelID,labelInnerText,value,isLocalizable); SelectChoice choice = new SelectChoice(label, value != null ? value : "dynamic:" + i, itemset.labelIsItext); choice.setIndex(i); if (itemset.copyMode) choice.copyNode = copyNode; choices.addElement(choice); } if (choices.size() == 0) { throw new RuntimeException( "dynamic select question has no choices! [" + itemset.nodesetRef + "]"); } itemset.setChoices(choices, this.getLocalizer()); }