use of org.akaza.openclinica.bean.submit.ResponseOptionBean in project OpenClinica by OpenClinica.
the class DataEntryInputGenerator method createCheckboxTag.
/*
* This method generates a checkbox tag for a cell inside an HTML table.
* Like the other methods, the user passes in a reference to the Element
* object, and the object receives new attributes and content. Then method
* returns the altered Element object. TODO: this code needs to be
* refactored to separate the domain or business rules from the rest of the
* parameters (e.g., isHorizontal)
*/
public Element createCheckboxTag(Element tdCell, Integer itemId, List options, Integer tabNumber, boolean includeLabel, String dbValue, String defaultValue, boolean isHorizontal, boolean hasSavedData) {
Element element;
String[] arrayOfValues = new String[] {};
// For keeping track of whether a checkbox is the first of a group
boolean isFirstInGroup;
int count = 0;
// Handles lone Strings, or Strings separated by commas
if (dbValue != null && dbValue.length() > 0) {
arrayOfValues = handleSplitString(dbValue);
} else if (!hasSavedData && defaultValue != null && defaultValue.length() > 0) {
arrayOfValues = handleSplitString(defaultValue);
}
for (Object responseOptBean : options) {
++count;
isFirstInGroup = count == 1;
element = this.initializeInputElement("checkbox", itemId, tabNumber);
String value = ((ResponseOptionBean) responseOptBean).getValue();
String forDefVal = ((ResponseOptionBean) responseOptBean).getText();
element.setAttribute("value", value);
// It's checked if its value equals the DB value
if (dbValue != null && dbValue.length() > 0) {
// && value.equalsIgnoreCase(dbValue)
for (String string : arrayOfValues) {
if (value.equalsIgnoreCase(string)) {
element.setAttribute("checked", "checked");
}
}
} else if (!hasSavedData && defaultValue != null && defaultValue.length() > 0) {
// && value.equalsIgnoreCase(dbValue)
for (String string : arrayOfValues) {
if (forDefVal.equalsIgnoreCase(string) || value.equalsIgnoreCase(string)) {
// ((ResponseOptionBean)responseOptBean).setSelected(true);
element.setAttribute("checked", "checked");
}
}
}
// is first in a group of checkboxes
if (!isHorizontal && isFirstInGroup) {
tdCell.addContent(new Element("br"));
}
tdCell.addContent(element);
if (includeLabel) {
tdCell.addContent(((ResponseOptionBean) responseOptBean).getText());
}
// <br> tag
if (!isHorizontal) {
tdCell.addContent(new Element("br"));
}
}
return tdCell;
}
Aggregations