use of org.akaza.openclinica.bean.submit.DisplaySectionBean in project OpenClinica by OpenClinica.
the class PrintAllSiteEventCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
// The PrintDataEntry servlet handles this parameter
int siteId = fp.getInt("siteId");
//JN:The following were the the global variables, moved as local.
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(getDataSource());
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
ArrayList<SectionBean> allSectionBeans;
StudyDAO studyDao = new StudyDAO(getDataSource());
StudyBean site = (StudyBean) studyDao.findByPK(siteId);
ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
seds = sedao.findAllByStudy(site);
// ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByStudy(site);
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
CRFDAO cdao = new CRFDAO(getDataSource());
boolean isSubmitted = false;
ArrayList<EventDefinitionCRFBean> edcs = new ArrayList();
for (StudyEventDefinitionBean sed : seds) {
int defId = sed.getId();
edcs.addAll(edcdao.findAllByDefinitionAndSiteIdAndParentStudyId(defId, siteId, site.getParentStudyId()));
}
Map eventDefinitionDefaultVersions = new LinkedHashMap();
Map eventDefinitionEventDefCrf = new LinkedHashMap<StudyEventDefinitionBean, EventDefinitionCRFBean>();
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = edcs.get(i);
if (!edc.getStatus().equals(Status.AVAILABLE)) {
continue;
}
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
// edc.setCrfLabel(crf.getLabel());
edc.setCrfName(crf.getName());
// to show/hide edit action on jsp page
if (crf.getStatus().equals(Status.AVAILABLE)) {
edc.setOwner(crf.getOwner());
}
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) sedao.findByPK(edc.getStudyEventDefinitionId());
edc.setDefaultVersionName(defaultVersion.getName());
if (defaultVersion.getStatus().isAvailable()) {
List list = (ArrayList) eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
if (list == null)
list = new ArrayList();
list.add(defaultVersion);
eventDefinitionDefaultVersions.put(studyEventDefinitionBean, list);
eventDefinitionEventDefCrf.put(studyEventDefinitionBean, edc);
}
}
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
SectionDAO sdao = new SectionDAO(getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
Map sedCrfBeans = null;
for (Iterator it = eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
if (sedCrfBeans == null)
sedCrfBeans = new LinkedHashMap();
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) it.next();
List crfVersions = (ArrayList) eventDefinitionDefaultVersions.get(sedBean);
for (Iterator crfIt = crfVersions.iterator(); crfIt.hasNext(); ) {
CRFVersionBean crfVersionBean = (CRFVersionBean) crfIt.next();
allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
CRFBean crfBean = crfDao.findByVersionId(crfVersionBean.getId());
if (itemGroupBeans.size() > 0) {
// get a DisplaySectionBean for each section of the CRF, sort
// them, then
// dispatch the request to a print JSP. The constructor for this
// handler takes
// a boolean value depending on whether data is involved or not
// ('false' in terms of this
// servlet; see PrintDataEntryServlet).
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionBean.getId());
//handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
request.setAttribute("crfVersionBean", crfverBean);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that data is not involved
request.setAttribute("dataInvolved", "false");
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setDisplaySectionBeans(displaySectionBeans);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setGrouped(true);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
continue;
}
ecb = new EventCRFBean();
ecb.setCRFVersionId(crfVersionBean.getId());
CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) eventDefinitionEventDefCrf.get(sedBean);
request.setAttribute(EVENT_DEF_CRF_BEAN, edcBean);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
sectionBeans = super.getAllDisplayBeans(request);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setAllSections(sectionBeans);
printCrfBean.setDisplaySectionBean(dsb);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setGrouped(false);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
}
}
StudyBean parentStudy = (StudyBean) studyDao.findByPK(site.getParentStudyId());
String studyName = parentStudy.getName();
String siteName = site.getName();
request.setAttribute("sedCrfBeans", sedCrfBeans);
request.setAttribute("studyName", studyName);
request.setAttribute("site", siteName);
forwardPage(Page.VIEW_ALL_SITE_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
use of org.akaza.openclinica.bean.submit.DisplaySectionBean in project OpenClinica by OpenClinica.
the class PrintCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
// The PrintDataEntry servlet handles this parameter
int eventCRFId = fp.getInt("ecId");
//JN:The following were the the global variables, moved as local.
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
// EventDefinitionCRFDao findByStudyEventIdAndCRFVersionId(int
// studyEventId, int crfVersionId)
SectionDAO sdao = new SectionDAO(getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
// The existing application doesn't print null values, even if they are
// defined in the event definition
int crfVersionId = fp.getInt("id", true);
boolean isSubmitted = false;
if (crfVersionId == 0) {
addPageMessage(respage.getString("please_choose_a_crf_to_view_details"), request);
forwardPage(Page.CRF_LIST_SERVLET, request, response);
} else {
// BWP 2/7/2008>> Find out if the CRF has grouped tables, and if so,
// use
// that dedicated JSP
ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionId);
if (itemGroupBeans.size() > 0) {
// get a DisplaySectionBean for each section of the CRF, sort
// them, then
// dispatch the request to a print JSP. The constructor for this
// handler takes
// a boolean value depending on whether data is involved or not
// ('false' in terms of this
// servlet; see PrintDataEntryServlet).
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionId);
handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
request.setAttribute("crfVersionBean", crfverBean);
CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that data is not involved
request.setAttribute("dataInvolved", "false");
// request.setAttribute("displaySection",displaySection);
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
// IllegalStateException
return;
}
//JN:Revisit ME
ecb = new EventCRFBean();
ecb.setCRFVersionId(crfVersionId);
CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
// super.sb = sb;
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
request.setAttribute(INPUT_EVENT_CRF, ecb);
sectionBeans = super.getAllDisplayBeans(request);
}
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
request.setAttribute("allSections", sectionBeans);
request.setAttribute("displayAllCRF", "1");
request.setAttribute(BEAN_DISPLAY, dsb);
request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
request.setAttribute("sec", sb);
request.setAttribute("EventCRFBean", ecb);
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
}
use of org.akaza.openclinica.bean.submit.DisplaySectionBean in project OpenClinica by OpenClinica.
the class DataEntryServlet method getAllDisplayBeans.
/**
* Retrieve the DisplaySectionBean which will be used to display the Event CRF Section on the JSP, and also is used to controll processRequest.
* @param request TODO
*/
protected ArrayList getAllDisplayBeans(HttpServletRequest request) throws Exception {
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
ArrayList sections = new ArrayList();
HttpSession session = request.getSession();
StudyBean study = (StudyBean) session.getAttribute("study");
SectionDAO sdao = new SectionDAO(getDataSource());
ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
// ALL_SECTION_BEANS
ArrayList<SectionBean> allSectionBeans = (ArrayList<SectionBean>) request.getAttribute(ALL_SECTION_BEANS);
for (int j = 0; j < allSectionBeans.size(); j++) {
SectionBean sb = allSectionBeans.get(j);
DisplaySectionBean section = new DisplaySectionBean();
section.setEventCRF(ecb);
if (sb.getParentId() > 0) {
SectionBean parent = (SectionBean) sdao.findByPK(sb.getParentId());
sb.setParent(parent);
}
section.setSection(sb);
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
section.setCrfVersion(cvb);
CRFDAO cdao = new CRFDAO(getDataSource());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
section.setCrf(cb);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
EventDefinitionCRFBean edcb = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), cvb.getId());
section.setEventDefinitionCRF(edcb);
// setup DAO's here to avoid creating too many objects
ItemDAO idao = new ItemDAO(getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
iddao = new ItemDataDAO(getDataSource(), locale);
// get all the display item beans
ArrayList displayItems = getParentDisplayItems(false, sb, edcb, idao, ifmdao, iddao, false, request);
LOGGER.debug("222 just ran get parent display, has group " + " FALSE has ungrouped FALSE");
// now sort them by ordinal
Collections.sort(displayItems);
// now get the child DisplayItemBeans
for (int i = 0; i < displayItems.size(); i++) {
DisplayItemBean dib = (DisplayItemBean) displayItems.get(i);
dib.setChildren(getChildrenDisplayItems(dib, edcb, request));
if (shouldLoadDBValues(dib)) {
LOGGER.trace("should load db values is true, set value");
dib.loadDBValue();
}
displayItems.set(i, dib);
}
section.setItems(displayItems);
sections.add(section);
}
return sections;
}
use of org.akaza.openclinica.bean.submit.DisplaySectionBean in project OpenClinica by OpenClinica.
the class TableTag method doTag.
@Override
public void doTag() throws JspException, IOException {
JspContext context = getJspContext();
JspWriter tagWriter = context.getOut();
boolean isViewData = datacontext != null && datacontext.equalsIgnoreCase(VIEW_DATA_ENTRY);
DisplaySectionBean dBean = (DisplaySectionBean) context.findAttribute("section");
StudyBean studyBean = (StudyBean) context.findAttribute("study");
// tabId is used to seed the tabindex attributes of the form's input
// elements,
// according to the section's tab number
int tabId;
// this is for viewDataEntryServlet
Object tabObject = context.findAttribute("tabId");
if (tabObject == null) {
// this is for DataEntryServlet
tabObject = context.findAttribute("tab");
}
if (tabObject == null) {
tabObject = new Integer("1");
}
tabId = new Integer(tabObject.toString());
if (dBean != null) {
HorizontalFormBuilder formBuilder = new HorizontalFormBuilder();
// FormBuilder sets tabindexSeed to 1 in its constructor
if (tabId > 1)
formBuilder.setTabindexSeed(tabId);
formBuilder.setDataEntry(isViewData);
formBuilder.setEventCRFbean(dBean.getEventCRF());
formBuilder.setDisplayItemGroups(dBean.getDisplayFormGroups());
formBuilder.setSectionBean(dBean.getSection());
if (studyBean != null) {
formBuilder.setStudyBean(studyBean);
}
tagWriter.println(formBuilder.createMarkup());
} else {
tagWriter.println("The section bean was not found<br />");
}
/*
* FormBuilderTest builder = new FormBuilderTest();
* tagWriter.println(builder.createTable());
*/
}
use of org.akaza.openclinica.bean.submit.DisplaySectionBean in project OpenClinica by OpenClinica.
the class PrintHorizontalFormBuilder method createMarkupNoDE.
/**
* Sequentially create a String of XML representing all of the sections on a
* Case Report Form, for the purpose of web-page display.
*
* @return A string representing the XML or XHTML.
*/
public String createMarkupNoDE() {
// data associated with it, pass on the responsibility to another object
ViewPersistanceHandler persistanceHandler = new ViewPersistanceHandler();
ViewBuilderPrintDecorator builderUtil = new ViewBuilderPrintDecorator();
// This object holds the printed output of the JDom Document object,
// which represents
// the XML for each section's HTML tables. The object is re-written
// each time a new section is generated
Writer writer = new StringWriter();
// This object contains all of the markup for all of the sections.
StringBuilder webPageBuilder = new StringBuilder();
// Keep track of the section number so we can create page numbers
int pageNumber = 0;
if (isInternetExplorer) {
for (DisplaySectionBean displaySecBean : this.displaySectionBeans) {
this.reconfigureView = builderUtil.hasThreePlusColumns(displaySecBean);
// reformulated for IE
if (reconfigureView)
break;
}
}
int uniqueId = 0;
// Print all the sections of a group-type table
for (DisplaySectionBean displaySecBean : this.displaySectionBeans) {
// The CellFactoryPrintDecorator object that generates the content
// for HTML table TD cells.
CellFactoryPrintDecorator cellFactory = new CellFactoryPrintDecorator();
// The object that handles the repetition model attributes for the
// HTML table elements
RepeatManager repeatManager = new RepeatManager();
// These classes "decorate" the FormBeanUtil and ViewBuilderUtil
// classes to
// provide special services required in printing
FormBeanUtilDecorator formUtilDecorator = new FormBeanUtilDecorator();
// Does this particular section have to be reconfigured for printing
// in IE browsers?
boolean changeHTMLForIE = false;
if (reconfigureView) {
// changeHTMLForIE = builderUtil.hasThreePlusColumns(displaySecBean);
}
++pageNumber;
sectionBean = displaySecBean.getSection();
if (involvesDataEntry) {
List<ItemDataBean> itemDataBeans;
persistanceHandler = new ViewPersistanceHandler();
itemDataBeans = persistanceHandler.fetchPersistedData(sectionBean.getId(), eventCRFbean.getId());
if (!itemDataBeans.isEmpty()) {
hasDbFormValues = true;
}
persistanceHandler.setItemDataBeans(itemDataBeans);
}
// Keep track of whether a group has any repeat behavior; true or
// false
boolean repeatFlag;
// The number of repeating table rows that the group will start
// with.
int repeatNumber;
// the div tag that will be the root node for each printable section
Element divRoot = new Element("div");
divRoot.setAttribute("id", ("toplevel" + pageNumber));
divRoot.setAttribute("class", "toplevel");
// remove float properties for IE browsers
if (isInternetExplorer) {
divRoot.setAttribute("style", "float:none");
}
Document doc = new Document(divRoot);
// Show the section's title, subtitle, or instructions
builderUtil.showTitles(divRoot, sectionBean, pageNumber, isInternetExplorer);
// One way to generate an id for the repeating tbody or tr element
// The tabindex attribute for select and input tags
int tabindex = 1;
// Should discrepancy note icons be displayed
boolean hasDiscrepancyMgt = false;
StudyBean studBean = this.getStudyBean();
if (studBean != null && studBean.getStudyParameterConfig().getDiscrepancyManagement().equalsIgnoreCase("true")) {
hasDiscrepancyMgt = true;
}
//Not to show discrepancy flags in the print crfs when there is no data
hasDiscrepancyMgt = false;
// its list of DisplayItemBeans
for (DisplayItemGroupBean displayItemGroup : displaySecBean.getDisplayFormGroups()) {
ArrayList headerlist = new ArrayList();
ArrayList bodylist = new ArrayList();
ArrayList subHeadList = new ArrayList();
List<DisplayItemBean> currentDisplayItems = displayItemGroup.getItems();
// A Map that contains persistent (stored in a database),
// repeated rows
// in a matrix type table
// The Map index is the Item id of the first member of the row;
// the value is a List
// of item beans that make up the row
SortedMap<Integer, List<ItemDataBean>> ordinalItemDataMap = new TreeMap<Integer, List<ItemDataBean>>();
// Is this a persistent matrix table and does it already have
// repeated rows
// in the database?
boolean hasStoredRepeatedRows = false;
// Is this a non-group type table that shares the same section
// as a group table?
// boolean unGroupedTable = displayItemGroup.getItemGroupBean().getName().equalsIgnoreCase(BeanFactory.UNGROUPED);
boolean unGroupedTable = displayItemGroup.getGroupMetaBean().isRepeatingGroup() ? false : true;
// Load any database values into the DisplayItemBeans
if (hasDbFormValues) {
currentDisplayItems = persistanceHandler.loadDataIntoDisplayBeans(currentDisplayItems, (!unGroupedTable));
/*
* The highest number ordinal represents how many repeated
* rows there are. If the ordinal in ItemDataBeans > 1, then
* we know that the group has persistent repeated rows. Get
* a structure that maps each ordinal (i.e., >= 2) to its
* corresponding List of ItemDataBeans. Then iterate the
* existing DisplayBeans, with the number of new rows
* equaling the highest ordinal number minus 1 (meaning, the
* first row represents the row of the group table that
* would exist if the user displayed the table, but didn't
* generate any new rows). For example, in a List of
* ItemDataBeans, if the highest ordinal property among
* these beans is 5, then the matrix table has 4 repeated
* rows from the database. Provide each new row with its
* values by using the ItemDataBeans.
*/
if (involvesDataEntry && !unGroupedTable && persistanceHandler.hasPersistentRepeatedRows(currentDisplayItems)) {
hasStoredRepeatedRows = true;
// if the displayitems contain duplicate item ids, then
// these duplicates
// represent repeated rows. Separate them into a Map of
// new rows that
// will be appended to the HTML table.
ordinalItemDataMap = persistanceHandler.handleExtraGroupRows();
}
}
// end if hasDbFormValues
// Does the table have a group header?
String groupHeader = displayItemGroup.getGroupMetaBean().getHeader();
boolean hasGroupHeader = groupHeader != null && groupHeader.length() > 0;
// Add group header, if there is one
if (hasGroupHeader) {
Element divGroupHeader = new Element("div");
// necessary?
divGroupHeader.setAttribute("class", "aka_group_header");
Element strong = new Element("strong");
strong.setAttribute("style", "float:none");
strong.addContent(groupHeader);
divGroupHeader.addContent(strong);
divRoot.addContent(divGroupHeader);
}
Element tableDiv = new Element("div");
tableDiv.setAttribute("class", "tableDiv");
if (isInternetExplorer) {
tableDiv.setAttribute("style", "float:none");
}
divRoot.addContent(tableDiv);
// This group represents "orphaned" items (those without a
// group) if
// the FormGroupBean has a group label of UNGROUPED
Element orphanTable = null;
if (unGroupedTable) {
orphanTable = formUtilDecorator.createXHTMLTableFromNonGroup(currentDisplayItems, tabindex, hasDiscrepancyMgt, hasDbFormValues, true);
// We have to track the point the tabindex has reached here
// The tabindex will increment by the size of the
// displayItemGroup List
tabindex += currentDisplayItems.size();
tableDiv.addContent(orphanTable);
continue;
}
// end if unGroupedTable
uniqueId++;
String repeatParentId = "repeatParent" + uniqueId;
repeatNumber = displayItemGroup.getGroupMetaBean().getRepeatNum();
// If the form has repeat behavior, this number is > 0
// Do not allow repeat numbers < 1
repeatNumber = repeatNumber < 1 ? 1 : repeatNumber;
// And a limit of 12
repeatNumber = repeatNumber > 12 ? 12 : repeatNumber;
// This is always true during this iteration
repeatFlag = true;
Element table = createTable();
// add the thead element
Element thead = new Element("tr");
tableDiv.addContent(table);
// table.addContent(thead);
// Does this group involve a Horizontal checkbox or radio
// button?
boolean hasResponseLayout = builderUtil.hasResponseLayout(currentDisplayItems);
// add th elements to the thead element
// We have to create an extra thead column for the Remove Row
// button, if
// the table involves repeating rows; thus the final boolean
// parameter
List<Element> thTags = repeatFlag ? createTheadContentsFromDisplayItems(currentDisplayItems, true) : createTheadContentsFromDisplayItems(currentDisplayItems, false);
int i = 0;
for (Element el : thTags) {
i++;
thead.addContent(el);
if (i % maxColRow == 0) {
headerlist.add(thead);
thead = new Element("tr");
}
}
if (i % maxColRow != 0)
headerlist.add(thead);
// in this manner.
if (hasResponseLayout) {
addResponseLayoutRow(subHeadList, currentDisplayItems);
}
Element row;
Element td;
// For each row in the table
row = new Element("tr");
// tag
if (repeatFlag && !(involvesDataEntry && hasStoredRepeatedRows)) {
table = repeatManager.addParentRepeatAttributes(table, repeatParentId, repeatNumber, displayItemGroup.getGroupMetaBean().getRepeatMax());
}
// The content for the table cells. For each item...
int j = 0;
for (DisplayItemBean displayBean : currentDisplayItems) {
j++;
// What type of input: text, radio, checkbox, etc.?
String responseName = displayBean.getMetadata().getResponseSet().getResponseType().getName();
// horizontal
if (displayBean.getMetadata().getResponseLayout().equalsIgnoreCase("horizontal") && (responseName.equalsIgnoreCase("checkbox") || responseName.equalsIgnoreCase("radio"))) {
// The final true parameter is for disabling D Notes
Element[] elements = cellFactory.createCellContentsForChecks(responseName, displayBean, displayBean.getMetadata().getResponseSet().getOptions().size(), ++tabindex, false, true);
for (Element el : elements) {
el = builderUtil.setClassNames(el);
if (repeatFlag) {
el = repeatManager.addChildRepeatAttributes(el, repeatParentId, displayBean.getItem().getId(), null);
}
row.addContent(el);
}
// move to the next item
continue;
}
td = new Element("td");
td = builderUtil.setClassNames(td);
// Create cells within each row
td = cellFactory.createCellContents(td, responseName, displayBean, ++tabindex, hasDiscrepancyMgt, hasDbFormValues, true);
if (repeatFlag) {
}
row.addContent(td);
if (j % maxColRow == 0) {
bodylist.add(row);
row = new Element("tr");
if (repeatFlag) {
repeatParentId = repeatParentId + uniqueId++;
}
}
}
// end for displayBean
if (j % maxColRow != 0)
bodylist.add(row);
//Creating the first/main table
if (hasStoredRepeatedRows) {
Element newRow = new Element("tr");
Element div = new Element("div");
div.setAttribute("id", "repeatCaption");
Element newCol = new Element("td");
Element strong = new Element("strong");
strong.addContent("Repeat: 1");
div.addContent(strong);
newCol.addContent(div);
newRow.addContent(newCol);
table.addContent(newRow);
}
if (!hasStoredRepeatedRows)
for (int ii = 0; ii < repeatNumber; ii++) {
divRoot.addContent(createTableWithoutData(bodylist, headerlist, subHeadList, ii, unGroupedTable));
}
// being clicked
if (hasStoredRepeatedRows) {
List storedRepeatedRows = builderUtil.generatePersistentMatrixRows(ordinalItemDataMap, currentDisplayItems, tabindex, repeatParentId, hasDiscrepancyMgt, true, maxColRow);
// add these new rows to the table
int count = 1;
for (int l = 0; l < storedRepeatedRows.size(); l++) {
++count;
List<Element> rowsList = (ArrayList) storedRepeatedRows.get(l);
divRoot.addContent(createTableWithData(rowsList, headerlist, subHeadList, count));
}
}
}
// end for displayFormGroup
XMLOutputter outp = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setOmitDeclaration(true);
outp.setFormat(format);
// The writer object contains the markup for one printable section
writer = new StringWriter();
try {
outp.output(doc, writer);
} catch (IOException e) {
e.printStackTrace();
}
// The webPageBuilder object contains the markup for all of the
// sections
// in the print view
webPageBuilder.append(writer.toString());
}
return webPageBuilder.toString();
}
Aggregations