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

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

Introduction

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

Prototype

public static void copyProperties(Object dest, Object orig)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo classes).

For more details see PropertyUtilsBean.

Usage

From source file:us.mn.state.health.lims.projectorganization.daoimpl.ProjectOrganizationDAOImpl.java

public void getData(ProjectOrganization projectOrg) throws LIMSRuntimeException {
    try {/* w w  w  .  java 2  s.c om*/
        ProjectOrganization data = (ProjectOrganization) HibernateUtil.getSession()
                .get(ProjectOrganization.class, projectOrg.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (data != null) {
            PropertyUtils.copyProperties(projectOrg, data);
        } else {
            projectOrg.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ProjectOrganizationDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in ProjectOrganization getData()", e);
    }
}

From source file:us.mn.state.health.lims.projectorganization.daoimpl.ProjectOrganizationDAOImpl.java

public void getDataByProject(ProjectOrganization projectOrganization) throws LIMSRuntimeException {

    try {/*from   w  w  w.  jav  a 2 s.  c  o  m*/
        String sql = "from ProjectOrganization so where project_id = :param";
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setParameter("param", projectOrganization.getProjectId());
        List list = query.list();
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        ProjectOrganization projOrgs = null;
        if (list.size() > 0) {
            projOrgs = (ProjectOrganization) list.get(0);
            PropertyUtils.copyProperties(projectOrganization, projOrgs);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ProjectOrganizationDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in ProjectOrganization getData()", e);
    }

}

From source file:us.mn.state.health.lims.provider.action.ProviderAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // The first job is to determine if we are coming to this action with an
    // ID parameter in the request. If there is no parameter, we are
    // creating a new Provider.
    // If there is a parameter present, we should bring up an existing
    // Provider to edit.

    String id = request.getParameter(ID);

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);//from   www . ja v  a2s.c  om

    Provider provider = new Provider();

    //System.out.println("I am in ProviderAction and this is id " + id);
    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // provider

        provider.setId(id);
        ProviderDAO providerDAO = new ProviderDAOImpl();
        providerDAO.getData(provider);
        // initialize selectedPersonId
        if (provider.getPerson() != null) {
            provider.setSelectedPersonId(provider.getPerson().getId());
        }
        isNew = false; // this is to set correct page title

        // do we need to enable next or previous?
        List providers = providerDAO.getNextProviderRecord(provider.getId());
        if (providers.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        providers = providerDAO.getPreviousProviderRecord(provider.getId());
        if (providers.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new provider

        isNew = true; // this is to set correct page title
    }

    if (provider.getId() != null && !provider.getId().equals("0")) {
        request.setAttribute(ID, provider.getId());
    }

    // populate form from valueholder
    PropertyUtils.copyProperties(form, provider);

    PersonDAO personDAO = new PersonDAOImpl();

    List persons = personDAO.getAllPersons();

    PropertyUtils.setProperty(form, "persons", persons);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.provider.action.ProviderUpdateAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // The first job is to determine if we are coming to this action with an
    // ID parameter in the request. If there is no parameter, we are
    // creating a new Provider.
    // If there is a parameter present, we should bring up an existing
    // Provider to edit.
    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "false");
    request.setAttribute(NEXT_DISABLED, "false");

    String id = request.getParameter(ID);

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
        isNew = true;/*ww  w  .  ja  va 2s. com*/
    } else {
        isNew = false;
    }

    // System.out.println("I am in ProviderUpdateAction");
    BaseActionForm dynaForm = (BaseActionForm) form;

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

    String start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

    // System.out.println("This is ID from request " + id);
    Provider provider = new Provider();
    //get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    provider.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    String selectedPersonId = (String) dynaForm.get("selectedPersonId");
    List persons = new ArrayList();
    if (dynaForm.get("persons") != null) {
        persons = (List) dynaForm.get("persons");
    } else {
        PersonDAO personDAO = new PersonDAOImpl();
        persons = personDAO.getAllPersons();
    }

    Person person = null;
    // get the right person to update provider with
    for (int i = 0; i < persons.size(); i++) {
        Person p = (Person) persons.get(i);
        if (p.getId().equals(selectedPersonId)) {
            person = p;
            break;
        }
    }

    // populate valueholder from form
    PropertyUtils.copyProperties(provider, dynaForm);

    provider.setPerson(person);

    try {

        ProviderDAO providerDAO = new ProviderDAOImpl();

        if (!isNew) {
            // UPDATE

            providerDAO.updateData(provider);
            if (FWD_NEXT.equals(direction)) {
                List providers = providerDAO.getNextProviderRecord(provider.getId());
                if (providers != null && providers.size() > 0) {
                    provider = (Provider) providers.get(0);
                    providerDAO.getData(provider);
                    if (providers.size() < 2) {
                        // disable next button
                        request.setAttribute(NEXT_DISABLED, "true");
                    }
                    id = provider.getId();
                } else {
                    // disable next button
                    request.setAttribute(NEXT_DISABLED, "true");
                }
                forward = FWD_NEXT;
            }

            if (FWD_PREVIOUS.equals(direction)) {
                List providers = providerDAO.getPreviousProviderRecord(provider.getId());
                if (providers != null && providers.size() > 0) {
                    provider = (Provider) providers.get(0);
                    providerDAO.getData(provider);
                    if (providers.size() < 2) {
                        // disable previous button
                        request.setAttribute(PREVIOUS_DISABLED, "true");
                    }
                    id = provider.getId();
                } else {
                    // disable previous button
                    request.setAttribute(PREVIOUS_DISABLED, "true");
                }
                forward = FWD_PREVIOUS;
            }
        } else {
            // INSERT

            providerDAO.insertData(provider);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ProviderUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        ActionError error = null;
        if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
            // how can I get popup instead of struts error at the top of
            // page?
            // ActionMessages errors = dynaForm.validate(mapping, request);
            error = new ActionError("errors.OptimisticLockException", null, null);
        } else {
            error = new ActionError("errors.UpdateException", null, null);
        }
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute(ALLOW_EDITS_KEY, "false");
        // disable previous and next
        request.setAttribute(PREVIOUS_DISABLED, "true");
        request.setAttribute(NEXT_DISABLED, "true");
        forward = FWD_FAIL;

    } finally {
        HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL))
        return mapping.findForward(forward);

    // initialize the form
    dynaForm.initialize(mapping);
    // repopulate the form from valueholder
    PropertyUtils.copyProperties(dynaForm, provider);

    PropertyUtils.setProperty(dynaForm, "persons", persons);

    if ("true".equalsIgnoreCase(request.getParameter("close"))) {
        forward = FWD_CLOSE;
    }

    if (provider.getId() != null && !provider.getId().equals("0")) {
        request.setAttribute(ID, provider.getId());

    }

    //bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    return getForward(mapping.findForward(forward), id, start);

}

From source file:us.mn.state.health.lims.provider.daoimpl.ProviderDAOImpl.java

public void getData(Provider provider) throws LIMSRuntimeException {
    try {/*from w  w  w  .java2s . c om*/
        Provider prov = (Provider) HibernateUtil.getSession().get(Provider.class, provider.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (prov != null) {
            PropertyUtils.copyProperties(provider, prov);
        } else {
            provider.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ProviderDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in Provider getData()", e);
    }
}

From source file:us.mn.state.health.lims.qaevent.action.QaEventAction.java

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

    String id = request.getParameter(ID);

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);/*w w  w.  j  a va 2  s  . c o m*/

    QaEvent qaEvent = new QaEvent();
    TestDAO testDAO = new TestDAOImpl();
    DictionaryDAO dictionaryDAO = new DictionaryDAOImpl();

    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // qaEvent

        qaEvent.setId(id);
        QaEventDAO qaEventDAO = new QaEventDAOImpl();
        qaEventDAO.getData(qaEvent);

        isNew = false; // this is to set correct page title

        // do we need to enable next or previous?
        List qaEvents = qaEventDAO.getNextQaEventRecord(qaEvent.getQaEventName());
        if (qaEvents.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }

        qaEvents = qaEventDAO.getPreviousQaEventRecord(qaEvent.getQaEventName());
        if (qaEvents.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else { // this is a new qaEvent

        isNew = true; // this is to set correct page title

    }

    if (qaEvent.getId() != null && !qaEvent.getId().equals("0")) {
        request.setAttribute(ID, qaEvent.getId());
    }
    //Get tests by user system id
    //bugzilla 2160
    UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl();
    //bugzilla 2291
    List tests = userTestSectionDAO.getAllUserTests(request, true);
    List dictionaries = dictionaryDAO.getDictionaryEntrysByCategory(
            SystemConfiguration.getInstance().getQaEventDictionaryCategoryType());
    //bugzilla 2506
    List dictionaries2 = dictionaryDAO.getDictionaryEntrysByCategory(
            SystemConfiguration.getInstance().getQaEventDictionaryCategoryCategory());

    //bugzilla 1856
    Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR);
    // populate form from valueholder
    PropertyUtils.copyProperties(form, qaEvent);
    PropertyUtils.setProperty(form, "tests", tests);
    PropertyUtils.setProperty(form, "dictionaries", dictionaries);
    //bugzilla 2506
    PropertyUtils.setProperty(form, "dictionaries2", dictionaries2);

    Test qaEventTest = (Test) qaEvent.getTest();
    // bugzilla 2246 changed name selectedTest to selectedTestId
    String selectedTestId = null;
    if (qaEventTest != null)
        selectedTestId = qaEventTest.getId();
    PropertyUtils.setProperty(form, "selectedTestId", selectedTestId);

    Dictionary type = (Dictionary) qaEvent.getType();
    String selectedTypeId = null;
    if (type != null)
        selectedTypeId = type.getId();
    // bugzilla 2246
    PropertyUtils.setProperty(form, "selectedTypeId", selectedTypeId);

    //bugzilla 2506
    Dictionary category = (Dictionary) qaEvent.getCategory();
    String selectedCategoryId = null;
    if (category != null)
        selectedCategoryId = category.getId();
    PropertyUtils.setProperty(form, "selectedCategoryId", selectedCategoryId);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryPositionToRecordAction.java

protected boolean getCurrentSampleFromList(List samples, Sample sample,
        boolean returnNextInListIfRecordNotFound) {
    boolean recordNotFound = true;
    if (samples != null && samples.size() > 0 && sample != null) {
        for (int i = 0; i < samples.size(); i++) {
            Sample sampleInList = (Sample) samples.get(i);
            if (sampleInList.getAccessionNumber().equals(sample.getAccessionNumber())) {
                recordNotFound = false;//from   ww  w .  java  2  s  . c  om
                return recordNotFound;
            }
        }
        //if we got to here then we didn't find the exact sample: get the  next higher accession number
        int accessionNumber = (Integer.valueOf(sample.getAccessionNumber())).intValue();
        for (int i = 0; i < samples.size(); i++) {
            Sample sampleInList = (Sample) samples.get(i);
            int accessionNumberFromList = (Integer.valueOf(sampleInList.getAccessionNumber())).intValue();
            if (accessionNumberFromList > accessionNumber) {
                Sample nextSample = (Sample) samples.get(i);
                try {
                    PropertyUtils.copyProperties(sample, nextSample);
                } catch (Exception e) {
                    //if this didn't work then say record not found
                }
                return recordNotFound;
            }
        }
        //if we got to here then we are beyond the last sample with qa events
        //now set to last record
        Sample lastSample = (Sample) samples.get(samples.size() - 1);
        try {
            PropertyUtils.copyProperties(sample, lastSample);
        } catch (Exception e) {
            //if this didn't work then say record not found
        }
    }

    return recordNotFound;
}

From source file:us.mn.state.health.lims.qaevent.action.QaEventUpdateAction.java

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

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "false");
    request.setAttribute(NEXT_DISABLED, "false");

    String id = request.getParameter(ID);

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
        isNew = true;/*ww w.  j a  v  a  2s .  com*/
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

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

    String start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

    QaEvent qaEvent = new QaEvent();
    // get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    qaEvent.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    // populate valueholder from form
    PropertyUtils.copyProperties(qaEvent, dynaForm);
    String selectedTestId = dynaForm.getString("selectedTestId");
    // Bugzilla 2246 added variable selectedTypeId
    String selectedTypeId = dynaForm.getString("selectedTypeId");
    //bugzilla 2506      
    String selectedCategoryId = dynaForm.getString("selectedCategoryId");

    QaEventDAO qaEventDAO = new QaEventDAOImpl();
    TestDAO testDAO = new TestDAOImpl();
    DictionaryDAO dictionaryDAO = new DictionaryDAOImpl();

    try {

        if (!StringUtil.isNullorNill(selectedTestId)) {
            Test selectedTest = new Test();
            selectedTest.setId(selectedTestId);
            testDAO.getData(selectedTest);
            qaEvent.setTest(selectedTest);
        }
        // Bugzilla 2246 set the type value for the valueholder 
        if (!StringUtil.isNullorNill(selectedTypeId)) {
            Dictionary selectedDictionary = new Dictionary();
            selectedDictionary.setId(selectedTypeId);
            dictionaryDAO.getData(selectedDictionary);
            qaEvent.setType(selectedDictionary);
        }

        // Bugzilla 2506 set the category value for the valueholder 
        if (!StringUtil.isNullorNill(selectedCategoryId)) {
            Dictionary selectedDictionary = new Dictionary();
            selectedDictionary.setId(selectedCategoryId);
            dictionaryDAO.getData(selectedDictionary);
            qaEvent.setCategory(selectedDictionary);
        }

        if (!isNew) {
            // UPDATE
            qaEventDAO.updateData(qaEvent);
        } else {
            // INSERT
            qaEventDAO.insertData(qaEvent);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("QaEventUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        ActionError error = null;
        if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
            error = new ActionError("errors.OptimisticLockException", null, null);
        } else {
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                java.util.Locale locale = (java.util.Locale) request.getSession()
                        .getAttribute("org.apache.struts.action.LOCALE");
                String messageKey = "qaevent.name";
                String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
                error = new ActionError("errors.DuplicateRecord", msg, null);

            } else {
                error = new ActionError("errors.UpdateException", null, null);
            }
        }
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        request.setAttribute(Globals.ERROR_KEY, errors);

        // disable previous and next
        request.setAttribute(PREVIOUS_DISABLED, "true");
        request.setAttribute(NEXT_DISABLED, "true");
        forward = FWD_FAIL;

    } finally {
        HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL))
        return mapping.findForward(forward);

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

    //Get tests by user system id
    //bugzilla 2160
    UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl();
    //bugzilla 2291
    List tests = userTestSectionDAO.getAllUserTests(request, true);
    //bugzilla 1856
    Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR);
    List dictionaries = dictionaryDAO.getDictionaryEntrysByCategory(
            SystemConfiguration.getInstance().getQaEventDictionaryCategoryType());
    //bugzilla 2506
    List dictionaries2 = dictionaryDAO.getDictionaryEntrysByCategory(
            SystemConfiguration.getInstance().getQaEventDictionaryCategoryCategory());

    // repopulate the form from valueholder
    PropertyUtils.copyProperties(dynaForm, qaEvent);
    PropertyUtils.setProperty(form, "tests", tests);
    PropertyUtils.setProperty(form, "dictionaries", dictionaries);
    //bugzilla 2506
    PropertyUtils.setProperty(form, "dictionaries2", dictionaries2);

    if ("true".equalsIgnoreCase(request.getParameter("close"))) {
        forward = FWD_CLOSE;
    }

    if (qaEvent.getId() != null && !qaEvent.getId().equals("0")) {
        request.setAttribute(ID, qaEvent.getId());

    }

    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    return getForward(mapping.findForward(forward), id, start, direction);
}

From source file:us.mn.state.health.lims.qaevent.daoimpl.QaEventDAOImpl.java

public void getData(QaEvent qaEvent) throws LIMSRuntimeException {
    try {/*from   w  w w  . j  ava2  s. c  o  m*/
        QaEvent qaEv = (QaEvent) HibernateUtil.getSession().get(QaEvent.class, qaEvent.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (qaEv != null) {
            PropertyUtils.copyProperties(qaEvent, qaEv);

        } else {
            qaEvent.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("QaEventDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in QaEvent getData()", e);
    }
}

From source file:us.mn.state.health.lims.receivercodeelement.action.ReceiverCodeElementAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // The first job is to determine if we are coming to this action with an
    // ID parameter in the request. If there is no parameter, we are
    // creating a new ReceiverCodeElement.
    // If there is a parameter present, we should bring up an existing
    // ReceiverCodeElement to edit.
    String id = request.getParameter(ID);

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);//w  w w  . jav a2 s . c  om

    ReceiverCodeElement receiverCodeElement = new ReceiverCodeElement();

    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // receiverCodeElement

        receiverCodeElement.setId(id);
        ReceiverCodeElementDAO receiverCodeElementDAO = new ReceiverCodeElementDAOImpl();
        receiverCodeElementDAO.getData(receiverCodeElement);

        isNew = false; // this is to set correct page title

        // initialize selectedMessageOrganizationId
        if (receiverCodeElement.getMessageOrganization() != null) {
            receiverCodeElement
                    .setSelectedMessageOrganizationId(receiverCodeElement.getMessageOrganization().getId());
        }
        if (receiverCodeElement.getCodeElementType() != null) {
            receiverCodeElement.setSelectedCodeElementTypeId(receiverCodeElement.getCodeElementType().getId());
        }

        // do we need to enable next or previous?
        //bugzilla 1427 pass in name not id
        List receiverCodeElements = receiverCodeElementDAO
                .getNextReceiverCodeElementRecord(receiverCodeElement.getId());
        if (receiverCodeElements.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        //bugzilla 1427 pass in name not id
        receiverCodeElements = receiverCodeElementDAO
                .getPreviousReceiverCodeElementRecord(receiverCodeElement.getId());
        if (receiverCodeElements.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new receiverCodeElement

        isNew = true; // this is to set correct page title

        //this is additional functionality to keep previously selected messageOrganizationId and codeElementTypeId for convenience
        String selectedMessageOrganizationId = (String) request.getParameter("selectedMessageOrganizationId");
        if (!StringUtil.isNullorNill(selectedMessageOrganizationId)) {
            receiverCodeElement.setSelectedMessageOrganizationId(selectedMessageOrganizationId);
        }
        String selectedCodeElementTypeId = (String) request.getParameter("selectedCodeElementTypeId");
        if (!StringUtil.isNullorNill(selectedCodeElementTypeId)) {
            receiverCodeElement.setSelectedCodeElementTypeId(selectedCodeElementTypeId);
        }

    }

    if (receiverCodeElement.getId() != null && !receiverCodeElement.getId().equals("0")) {
        request.setAttribute(ID, receiverCodeElement.getId());
    }

    // populate form from valueholder
    PropertyUtils.copyProperties(form, receiverCodeElement);

    MessageOrganizationDAO messageOrganizationDAO = new MessageOrganizationDAOImpl();
    List messageOrganizations = messageOrganizationDAO.getAllMessageOrganizations();
    PropertyUtils.setProperty(form, "messageOrganizations", messageOrganizations);

    CodeElementTypeDAO codeElementTypeDAO = new CodeElementTypeDAOImpl();
    List codeElementTypes = codeElementTypeDAO.getAllCodeElementTypes();
    PropertyUtils.setProperty(form, "codeElementTypes", codeElementTypes);

    return mapping.findForward(forward);
}