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.receivercodeelement.action.ReceiverCodeElementUpdateAction.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 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;//from   w w w.  j  a  va 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) {
        // System.out.println("Server side validation errors "
        // + errors.toString());
        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);
    ReceiverCodeElement receiverCodeElement = new ReceiverCodeElement();
    //get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    receiverCodeElement.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

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

    // get messageOrganization valueholder to be set in receiverCodeElement
    String messageOrganizationId = (String) dynaForm.get("selectedMessageOrganizationId");
    List messageOrganizations = new ArrayList();
    if (dynaForm.get("messageOrganizations") != null) {
        messageOrganizations = (List) dynaForm.get("messageOrganizations");
    } else {
        MessageOrganizationDAO messageOrganizationDAO = new MessageOrganizationDAOImpl();
        messageOrganizations = messageOrganizationDAO.getAllMessageOrganizations();
    }
    MessageOrganization messageOrganization = null;
    for (int i = 0; i < messageOrganizations.size(); i++) {
        MessageOrganization refTbl = (MessageOrganization) messageOrganizations.get(i);
        if (refTbl.getId().equals(messageOrganizationId)) {
            messageOrganization = refTbl;
            break;
        }
    }
    receiverCodeElement.setMessageOrganization(messageOrganization);

    // get codeElementType valueholder to be set in codeElementXref
    String codeElementTypeId = (String) dynaForm.get("selectedCodeElementTypeId");
    List codeElementTypes = new ArrayList();
    if (dynaForm.get("codeElementTypes") != null) {
        codeElementTypes = (List) dynaForm.get("codeElementTypes");
    } else {
        CodeElementTypeDAO codeElementTypeDAO = new CodeElementTypeDAOImpl();
        codeElementTypes = codeElementTypeDAO.getAllCodeElementTypes();
    }
    CodeElementType codeElementType = null;
    for (int i = 0; i < codeElementTypes.size(); i++) {
        CodeElementType cet = (CodeElementType) codeElementTypes.get(i);
        if (cet.getId().equals(codeElementTypeId)) {
            codeElementType = cet;
            break;
        }
    }
    receiverCodeElement.setCodeElementType(codeElementType);

    try {

        ReceiverCodeElementDAO receiverCodeElementDAO = new ReceiverCodeElementDAOImpl();

        if (!isNew) {
            // UPDATE

            receiverCodeElementDAO.updateData(receiverCodeElement);

        } else {
            // INSERT

            receiverCodeElementDAO.insertData(receiverCodeElement);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ReceiverCodeElementDeleteAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        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 {
            // bugzilla 1482
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "receiverCodeElement.receiverCodeElement";
                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);
        //bugzilla 1485: allow change and try updating again (enable save button)
        //request.setAttribute(IActionConstants.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, receiverCodeElement);

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

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

    }

    //bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    //bugzilla 1467 added direction for redirect to NextPreviousAction
    return getForward(mapping.findForward(forward), id, start, direction, messageOrganizationId,
            codeElementTypeId);

}

From source file:us.mn.state.health.lims.receivercodeelement.daoimpl.ReceiverCodeElementDAOImpl.java

public void getData(ReceiverCodeElement receiverCodeElement) throws LIMSRuntimeException {
    try {//w  w w . j  a  v  a 2s .com
        ReceiverCodeElement pan = (ReceiverCodeElement) HibernateUtil.getSession()
                .get(ReceiverCodeElement.class, receiverCodeElement.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (pan != null) {
            PropertyUtils.copyProperties(receiverCodeElement, pan);
        } else {
            receiverCodeElement.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ReceiverCodeElementDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in ReceiverCodeElement getData()", e);
    }

}

From source file:us.mn.state.health.lims.referencetables.action.ReferenceTablesAction.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 Gender.
    // If there is a parameter present, we should bring up an existing
    // Gender 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  ww .j  a  v a  2 s . c  o  m

    ReferenceTables referenceTables = new ReferenceTables();
    //System.out.println("I am in ReferenceTablesAction and this is id " + id);
    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // gender

        referenceTables.setId(id);
        ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();
        referenceTablesDAO.getData(referenceTables);

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

        // do we need to enable next or previous?
        List referenceTableses = referenceTablesDAO.getNextReferenceTablesRecord(referenceTables.getId());
        if (referenceTableses.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        referenceTableses = referenceTablesDAO.getPreviousReferenceTablesRecord(referenceTables.getId());
        if (referenceTableses.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else { // this is a new gender

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

    }

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

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

    //System.out.println("I am in GenderAction this is forward " + forward);
    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.referencetables.action.ReferenceTablesUpdateAction.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 Gender.
    // If there is a parameter present, we should bring up an existing
    // Gender 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);

    //get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
        isNew = true;/*from   w w  w  .ja  v a  2s .  c o  m*/
    } 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");

    ReferenceTables referenceTables = new ReferenceTables();
    referenceTables.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    // populate object from form
    PropertyUtils.copyProperties(referenceTables, dynaForm);

    try {
        ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();

        if (!isNew) {
            // UPDATE
            referenceTablesDAO.updateData(referenceTables);
        } else {
            // INSERT
            referenceTablesDAO.insertData(referenceTables);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ReferenceTablesUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        //bugzilla 1482
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        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 {
            // bugzilla 1482
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "referenceTables.tableName";
                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);
        //bugzilla 1485: allow change and try updating again (enable save button)
        //request.setAttribute(IActionConstants.ALLOW_EDITS_KEY, "false");
        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, referenceTables);

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

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

    }

    //bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    //bugzilla 1467 added direction for redirect to NextPreviousAction
    return getForward(mapping.findForward(forward), id, start, direction);

}

From source file:us.mn.state.health.lims.referencetables.daoimpl.ReferenceTablesDAOImpl.java

public void getData(ReferenceTables referenceTables) throws LIMSRuntimeException {
    try {/*www. ja v  a  2s .  c  om*/
        ReferenceTables reftbl = (ReferenceTables) HibernateUtil.getSession().get(ReferenceTables.class,
                referenceTables.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (reftbl != null) {
            PropertyUtils.copyProperties(referenceTables, reftbl);
        } else {
            referenceTables.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ReferenceTablesDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in Referencetables getData()", e);
    }
}

From source file:us.mn.state.health.lims.region.action.RegionAction.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 Region.
    // If there is a parameter present, we should bring up an existing
    // Region 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  w  w  w .  ja v  a  2  s  .c  o m*/

    Region region = new Region();

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

        region.setId(id);
        RegionDAO regionDAO = new RegionDAOImpl();
        regionDAO.getData(region);
        isNew = false; // this is to set correct page title

        // do we need to enable next or previous?
        //bugzilla 1427 pass in name not id
        List regions = regionDAO.getNextRegionRecord(region.getRegion());
        if (regions.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        //bugzilla 1427 pass in name not id
        regions = regionDAO.getPreviousRegionRecord(region.getRegion());
        if (regions.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else { // this is a new region
        isNew = true; // this is to set correct page title
    }

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

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

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.region.action.RegionUpdateAction.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 Region.
    // If there is a parameter present, we should bring up an existing
    // Region 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;/*from w ww .  j ava  2 s . c om*/
    } 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");

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

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

    try {

        RegionDAO regionDAO = new RegionDAOImpl();

        if (!isNew) {
            // UPDATE

            regionDAO.updateData(region);
        } else {
            // INSERT

            regionDAO.insertData(region);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("RegionUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        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 {
            // bugzilla 1482
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "region.region";
                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);
        //bugzilla 1485: allow change and try updating again (enable save button)
        //request.setAttribute(IActionConstants.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, region);

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

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

    }

    //bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    //bugzilla 1467 added direction for redirect to NextPreviousAction
    return getForward(mapping.findForward(forward), id, start, direction);

}

From source file:us.mn.state.health.lims.region.daoimpl.RegionDAOImpl.java

public void getData(Region region) throws LIMSRuntimeException {
    try {//  w w w .ja va2  s  .co m
        Region reg = (Region) HibernateUtil.getSession().get(Region.class, region.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (reg != null) {
            PropertyUtils.copyProperties(region, reg);
        } else {
            region.setId(null);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("RegionDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in Region getData()", e);
    }
}

From source file:us.mn.state.health.lims.renametestsection.action.RenameTestSectionAction.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 TestSection.
    // If there is a parameter present, we should bring up an existing
    // TestSection 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.java  2 s.c  o  m*/

    RenameTestSection testSection = new RenameTestSection();

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

        testSection.setId(id);
        RenameTestSectionDAO testSectionDAO = new RenameTestSectionDAOImpl();
        testSectionDAO.getData(testSection);

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

        // do we need to enable next or previous?
        //bugzilla 1427 pass in name not id
        List testSections = testSectionDAO.getNextTestSectionRecord(testSection.getTestSectionName());
        if (testSections.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        //bugzilla 1427 pass in name not id
        testSections = testSectionDAO.getPreviousTestSectionRecord(testSection.getTestSectionName());
        if (testSections.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else { // this is a new testSection

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

    }

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

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

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.renametestsection.action.RenameTestSectionUpdateAction.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 TestSection.
    // If there is a parameter present, we should bring up an existing
    // TestSection 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;/*from  w ww .j  av a 2s .  c  o  m*/
    } 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");

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

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

    try {

        RenameTestSectionDAO testSectionDAO = new RenameTestSectionDAOImpl();

        if (!isNew) {
            // UPDATE
            testSectionDAO.updateData(testSection);

        } else {
            // INSERT
            testSectionDAO.insertData(testSection);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("TestSectionUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        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 {
            // bugzilla 1482
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "testsection.testSectionName";
                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);
        //bugzilla 1485: allow change and try updating again (enable save button)
        //request.setAttribute(IActionConstants.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, testSection);

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

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

    }

    //bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    //bugzilla 1467 added direction for redirect to NextPreviousAction
    return getForward(mapping.findForward(forward), id, start, direction);

}