}
Collection chosen = getChosen(editorResources);
Template optionBlock = template.getBlock("option");
Iterator iter = this.options.iterator();
for(int i=0; i<this.options.size(); i++) {
SelectOption opt = (SelectOption) iter.next();
optionBlock.setVariable("id", editorResources.getWriteId());
//write the option's description
String desc = opt.getLabel(labelResource);
optionBlock.setVariable("description", desc);
try {
//write the option's value
String optValue;
if(formatter == null)
optValue = opt.getValue().toString();
else
optValue = formatter.valueToString(opt.getValue(), editorResources);
optionBlock.setVariable("value", optValue);
//check if this option is currently selected/chosen
//here's a small trick, in some cases the opts values
//might not be directly of same type as the
//propertytype, example the optvalues might be Strings
//containing integers and propertytype might be
//integer. So we use the formatter here before
//comparison to convert the optString's to correct format.
if(formatter == null && chosen.contains(opt.getValue()))
optionBlock.getBlock("selected").write();
else if(formatter != null) {
String tmp = formatter.valueToString(opt.getValue(), editorResources);
Object tmp2 = formatter.stringToValue(tmp, editorResources);
if(chosen.contains(tmp2))
optionBlock.getBlock("selected").write();
}
} catch(FormatterException e) {
//mark option as erroneus, set error message to the description
optionBlock.setVariable("cssClass", "error");
optionBlock.setVariable("description", desc + " :"
+ e.getMessage());
}
//useful for CheckBoxGroupEditor
if(useColumns() && (i + 1) % getColumns() == 0) {
optionBlock.getBlock("rowchange").write();
}
optionBlock.write();
}
super.writeEditorErrors(template, editorResources);
template.write();
return template.toString();