Search in sources :

Example 31 with ResponseOptionBean

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;
}
Also used : Element(org.jdom.Element) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Aggregations

ResponseOptionBean (org.akaza.openclinica.bean.submit.ResponseOptionBean)31 ArrayList (java.util.ArrayList)20 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)9 Element (org.jdom.Element)8 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)7 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)5 HashMap (java.util.HashMap)4 NumberFormat (java.text.NumberFormat)3 Iterator (java.util.Iterator)3 NullValue (org.akaza.openclinica.bean.core.NullValue)3 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)3 DisplayItemWithGroupBean (org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean)3 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)3 Random (java.util.Random)2 HttpSession (javax.servlet.http.HttpSession)2 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)2 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)2 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)2