catch (Exception ex) {
throw new RuntimeException("Error in answer list for concept " + concept.getConceptId() + " ("
+ ex.toString() + "): " + conceptAnswers);
}
}
ConceptNumeric cn;
if (concept instanceof ConceptNumeric) {
cn = (ConceptNumeric) concept;
} else {
cn = Context.getConceptService().getConceptNumeric(concept.getConceptId());
}
// added to avoid creating this widget when a checkbox is needed
if (numericAnswers.size() == 0) {
if (!"checkbox".equals(parameters.get("style"))) {
valueWidget = new NumberFieldWidget(cn, parameters.get("size"));
} else {
// render CheckboxWidgets for <obs> tag with numeric datatype;
// i.e. <obs conceptId="1234" answer="8" answerLabel="Eight" style="checkbox"/>
if (parameters.get("answer") != null) {
try {
Number number = Double.valueOf(parameters.get("answer"));
numericAnswers.add(number);
answerLabel = parameters.get("answerLabel");
if (number != null) {
valueWidget = new CheckboxWidget(answerLabel, number.toString());
}
} catch (Exception ex) {
throw new RuntimeException("Error in answer for concept " + concept.getConceptId() + " ("
+ ex.toString() + "): ");
}
}
}
} else {
if ("radio".equals(parameters.get("style"))) {
valueWidget = new RadioButtonsWidget();
if (answerSeparator != null) {
((RadioButtonsWidget) valueWidget).setAnswerSeparator(answerSeparator);
}
} else { // dropdown
valueWidget = buildDropdownWidget(size);
}
// need to make sure we have the initialValue too
Number lookFor = existingObs == null ? null : existingObs.getValueNumeric();
for (int i = 0; i < numericAnswers.size(); ++i) {
Number n = numericAnswers.get(i);
if (lookFor != null && lookFor.equals(n))
lookFor = null;
String label = null;
if (answerLabels != null && i < answerLabels.size()) {
label = answerLabels.get(i);
} else {
label = n.toString();
}
((SingleOptionWidget) valueWidget).addOption(new Option(label, n.toString(), false));
}
// if lookFor is still non-null, we need to add it directly as
// an option:
if (lookFor != null)
((SingleOptionWidget) valueWidget)
.addOption(new Option(lookFor.toString(), lookFor.toString(), true));
}
if (valueWidget != null) {
boolean isPrecise = cn != null ? cn.isPrecise() : true; // test data is missing concept numerics
Number initialValue = null;
if (existingObs != null && existingObs.getValueNumeric() != null) {
// for non-precise numeric obs, initial value should be rendered as an integer
initialValue = isPrecise ? ((Number) existingObs.getValueNumeric()) : existingObs.getValueNumeric().intValue();