Example usage for org.apache.commons.beanutils PropertyUtils setProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils setProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils setProperty.

Prototype

public static void setProperty(Object bean, String name, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:us.mn.state.health.lims.reports.action.AuditTrailSystemTestProcessAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);
    if (errors != null && errors.size() > 0) {
        saveErrors(request, errors);//  w  w w.  ja v  a  2s.  co m
        // since we forward to jsp - not Action we don't need to repopulate
        // the lists here
        return mapping.findForward(FWD_FAIL);
    }

    request.setAttribute(ALLOW_EDITS_KEY, "false");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    AuditTrailDAO auditTrailDAO = new AuditTrailDAOImpl();
    SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
    //ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();

    String systemUserId = (String) dynaForm.getString("selectedSystemUserId");

    String referenceTableId = null;
    if (dynaForm.getString("selectedReferenceTableId") != null) {
        referenceTableId = (String) dynaForm.getString("selectedReferenceTableId");
        //ReferenceTables referenceTables = new ReferenceTables();
        //referenceTables.setId(referenceTableId);
        //referenceTablesDAO.getData(referenceTables);

    }

    String dateModified = (String) dynaForm.getString("dateModified");
    List systemUsers = (ArrayList) dynaForm.get("systemUsers");
    List referenceTableList = (ArrayList) dynaForm.get("referenceTableList");

    History history = new History();
    history.setSysUserId(systemUserId);
    if (!StringUtil.isNullorNill(referenceTableId)) {
        history.setReferenceTable(referenceTableId);
    }
    String locale = SystemConfiguration.getInstance().getDefaultLocale().toString();
    history.setTimestamp(DateUtil.convertStringDateToTruncatedTimestamp(dateModified, locale));

    @SuppressWarnings("unchecked")
    List<History> historyRecords = auditTrailDAO.getHistoryBySystemUserAndDateAndRefTableId(history);
    ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();

    List<HistoryXmlHelper> historyRecordsForDisplay = new ArrayList<HistoryXmlHelper>();
    for (History h : historyRecords) {
        HistoryXmlHelper historyXmlHelper = new HistoryXmlHelper();
        historyXmlHelper.setActivity(h.getActivity());
        ReferenceTables ref = new ReferenceTables();
        ref.setId(h.getReferenceTable());
        referenceTablesDAO.getData(ref);
        historyXmlHelper.setReferenceTableName(ref.getTableName());
        historyXmlHelper.setReferenceTableId(h.getReferenceId());
        SystemUser systemUser = new SystemUser();
        systemUser.setId(h.getSysUserId());
        systemUserDAO.getData(systemUser);

        historyXmlHelper.setUserName(systemUser.getNameForDisplay());
        historyXmlHelper.setDate(DateUtil.convertTimestampToStringDateAndTime(h.getTimestamp(), locale));
        if (!historyXmlHelper.getActivity().equals(IActionConstants.AUDIT_TRAIL_INSERT))
            historyXmlHelper.setChange(auditTrailDAO.retrieveBlobData(h.getId()));
        historyRecordsForDisplay.add(historyXmlHelper);
    }

    // initialize the form
    dynaForm.initialize(mapping);

    PropertyUtils.setProperty(dynaForm, "historyRecords", historyRecordsForDisplay);

    PropertyUtils.setProperty(form, "referenceTableList", referenceTableList);
    PropertyUtils.setProperty(form, "systemUsers", systemUsers);

    PropertyUtils.setProperty(dynaForm, "selectedSystemUserId", systemUserId);
    PropertyUtils.setProperty(dynaForm, "selectedReferenceTableId", referenceTableId);
    PropertyUtils.setProperty(dynaForm, "dateModified", dateModified);

    forward = FWD_SUCCESS;

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.reports.action.CommonReportAction.java

@Override
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    BaseActionForm dynaForm = (BaseActionForm) form;

    dynaForm.initialize(mapping);/*from  www . jav  a  2s  .  com*/
    PropertyUtils.setProperty(dynaForm, "reportType", request.getParameter("type"));
    PropertyUtils.setProperty(dynaForm, "reportRequest", request.getParameter("report"));
    IReportParameterSetter setter = ReportImplementationFactory
            .getParameterSetter(request.getParameter("report"));

    if (setter != null) {
        setter.setRequestParameters(dynaForm);
    }

    return mapping.findForward(FWD_SUCCESS);
}

From source file:us.mn.state.health.lims.reports.action.CommonReportPrintAction.java

@SuppressWarnings("unchecked")
@Override//from   w  ww.jav  a  2 s  . com
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    BaseActionForm dynaForm = (BaseActionForm) form;

    PropertyUtils.setProperty(dynaForm, "reportType", request.getParameter("type"));

    IReportCreator reportCreator = ReportImplementationFactory.getReportCreator(request.getParameter("report"));

    String forward = FWD_FAIL;

    if (reportCreator != null) {
        reportCreator.initializeReport(dynaForm);
        reportCreator.setReportPath(getReportPath());

        HashMap<String, String> parameterMap = (HashMap<String, String>) reportCreator.getReportParameters();
        parameterMap.put("SUBREPORT_DIR", getReportPath());

        try {

            response.setContentType(reportCreator.getContentType());
            String responseHeaderName = reportCreator.getResponseHeaderName();
            String responseHeaderContent = reportCreator.getResponseHeaderContent();
            if (!GenericValidator.isBlankOrNull(responseHeaderName)
                    && !GenericValidator.isBlankOrNull(responseHeaderContent)) {
                response.setHeader(responseHeaderName, responseHeaderContent);
            }

            byte[] bytes = reportCreator.runReport();

            response.setContentLength(bytes.length);

            ServletOutputStream servletOutputStream = response.getOutputStream();

            servletOutputStream.write(bytes, 0, bytes.length);
            servletOutputStream.flush();
            servletOutputStream.close();
        } catch (Exception e) {
            LogEvent.logErrorStack("CommonReportPrintAction", "performAction", e);
            e.printStackTrace();
        }
    }

    if ("patient".equals(request.getParameter("type"))) {
        trackReports(reportCreator, request.getParameter("report"), ReportType.PATIENT);
    }

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.reports.action.implementation.DateRangeParameters.java

@Override
public void setRequestParameters(BaseActionForm dynaForm) {
    try {/* w w w .j a  v a2s.c  om*/
        PropertyUtils.setProperty(dynaForm, "reportName", reportTitle);
        PropertyUtils.setProperty(dynaForm, "useLowerDateRange", true);
        PropertyUtils.setProperty(dynaForm, "useUpperDateRange", true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:us.mn.state.health.lims.reports.action.implementation.ExportProjectByDate.java

public void setRequestParameters(BaseActionForm dynaForm) {
    try {/*from  w  w  w . j a va 2 s.  c  o  m*/
        PropertyUtils.setProperty(dynaForm, "reportName", getReportNameForParameterPage());
        PropertyUtils.setProperty(dynaForm, "useLowerDateRange", Boolean.TRUE);
        PropertyUtils.setProperty(dynaForm, "useUpperDateRange", Boolean.TRUE);
        PropertyUtils.setProperty(dynaForm, "useProjectCode", Boolean.TRUE);
        PropertyUtils.setProperty(dynaForm, "projectCodeList", getProjectList());
    } catch (Exception e) {
        Log.error("Error in ExportProjectByDate.setRequestParemeters: ", e);
    }
}

From source file:us.mn.state.health.lims.reports.action.implementation.HaitiExportReport.java

public void setRequestParameters(BaseActionForm dynaForm) {
    try {/*from  www  .  ja  v  a 2 s.  c o  m*/
        PropertyUtils.setProperty(dynaForm, "reportName", getReportNameForParameterPage());
        PropertyUtils.setProperty(dynaForm, "useLowerDateRange", Boolean.TRUE);
        PropertyUtils.setProperty(dynaForm, "useUpperDateRange", Boolean.TRUE);
    } catch (Exception e) {
        Log.error("Error in " + this.getClass().getSimpleName() + ".setRequestParemeters: ", e);
    }
}

From source file:us.mn.state.health.lims.reports.action.implementation.HaitiIndicatorReport.java

public void setRequestParameters(BaseActionForm dynaForm) {
    try {/*from   w  w w.ja va  2s. c o m*/
        PropertyUtils.setProperty(dynaForm, "reportName", getNameForReportRequest());

        PropertyUtils.setProperty(dynaForm, "useLowerDateRange", Boolean.TRUE);
        PropertyUtils.setProperty(dynaForm, "useUpperDateRange", Boolean.TRUE);

        PropertyUtils.setProperty(dynaForm, "exportOptions", getExportOptions());
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}

From source file:us.mn.state.health.lims.reports.action.implementation.HaitiPatientReport.java

public void setRequestParameters(BaseActionForm dynaForm) {
    try {/*  w  w w  . j ava2s . c o m*/
        PropertyUtils.setProperty(dynaForm, "reportName", getReportNameForParameterPage());

        PropertyUtils.setProperty(dynaForm, "useAccessionDirect", Boolean.TRUE);
        PropertyUtils.setProperty(dynaForm, "useHighAccessionDirect", Boolean.TRUE);
        PropertyUtils.setProperty(dynaForm, "usePatientNumberDirect", Boolean.TRUE);

        PropertyUtils.setProperty(dynaForm, "exportOptions", getExportOptions());
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}

From source file:us.mn.state.health.lims.reports.action.implementation.IndicatorHaitiSiteTestCountReport.java

@Override
public void setRequestParameters(BaseActionForm dynaForm) {
    try {//from w w w . j a v a 2s.  com
        PropertyUtils.setProperty(dynaForm, "usePredefinedDateRanges", Boolean.TRUE);
        new ReportSpecificationList(getSiteList(), StringUtil.getMessageForKey("report.select.site"))
                .setRequestParameters(dynaForm);
        PropertyUtils.setProperty(dynaForm, "instructions",
                StringUtil.getMessageForKey("report.instruction.inventory.test.count"));
        PropertyUtils.setProperty(dynaForm, "monthList", MONTH_LIST);
        PropertyUtils.setProperty(dynaForm, "yearList", getYearList());
    } catch (Exception e) {
        e.printStackTrace();
    }

}