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.patient.action.BasePatientEntryByProject.java

/**
 * various maps full of a various lists used by the patient entry form (typically for drop downs) and other forms who want to do patient entry.
 * @throws Exception all from setProperty problems caused by developer mistakes.
 *//*from ww  w . j a v a2s .  co  m*/
public static Map<String, Object> addAllPatientFormLists(BaseActionForm dynaForm) throws Exception {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("GENDERS", PatientUtil.findGenders());

    PropertyUtils.setProperty(dynaForm, "formLists", resultMap);
    PropertyUtils.setProperty(dynaForm, "dictionaryLists", ObservationHistoryList.MAP);
    PropertyUtils.setProperty(dynaForm, "organizationTypeLists", OrganizationTypeList.MAP);

    return resultMap;
}

From source file:us.mn.state.health.lims.patient.action.PatientAction.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 Patient.
    // If there is a parameter present, we should bring up an existing
    // Patient 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 a2  s  . co m*/

    Patient patient = new Patient();

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

        patient.setId(id);
        PatientDAO patientDAO = new PatientDAOImpl();
        patientDAO.getData(patient);
        // initialize selectedPersonId
        if (patient.getPerson() != null) {
            patient.setSelectedPersonId(patient.getPerson().getId());
        }
        isNew = false; // this is to set correct page title

        // do we need to enable next or previous?
        List patients = patientDAO.getNextPatientRecord(patient.getId());
        if (patients.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        patients = patientDAO.getPreviousPatientRecord(patient.getId());
        if (patients.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else { // this is a new patient

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

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

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

    PersonDAO personDAO = new PersonDAOImpl();
    GenderDAO genderDAO = new GenderDAOImpl();

    List persons = personDAO.getAllPersons();
    List genders = genderDAO.getAllGenders();

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

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.patient.action.PatientEditByProjectAction.java

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

    todayAsText = DateUtil.formatDateAsText(new Date());

    String forward = "success";

    BaseActionForm dynaForm = (BaseActionForm) form;

    request.getSession().setAttribute(IActionConstants.SAVE_DISABLED, IActionConstants.TRUE);

    // Initialize the form.
    dynaForm.initialize(mapping);//w  ww .j a  va 2  s  .  c om

    updateRequestType(request);

    // Set current date and entered date to today's date      
    PropertyUtils.setProperty(form, "currentDate", todayAsText); // TODO Needed?

    addAllPatientFormLists(dynaForm);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.patient.action.PatientEntryByProjectAction.java

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

    todayAsText = DateUtil.formatDateAsText(new Date());

    String forward = "success";

    BaseActionForm dynaForm = (BaseActionForm) form;

    request.getSession().setAttribute(IActionConstants.SAVE_DISABLED, IActionConstants.TRUE);

    // retrieve the current project, before clearing, so that we can set it on later.
    String projectFormName = Accessioner.findProjectFormName(dynaForm);
    // Initialize the form.
    dynaForm.initialize(mapping);//from w  ww.j  a  va 2s .c  o  m
    updateRequestType(request);

    addAllPatientFormLists(dynaForm);

    PropertyUtils.setProperty(form, "currentDate", todayAsText); // TODO Needed?
    PropertyUtils.setProperty(form, "receivedDateForDisplay", todayAsText);
    PropertyUtils.setProperty(form, "interviewDate", todayAsText);
    // put the projectFormName back in.
    setProjectFormName(form, projectFormName);
    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.patient.action.PatientManagementAction.java

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

    String forward = "success";

    request.getSession().setAttribute(IActionConstants.SAVE_DISABLED, IActionConstants.TRUE);

    BaseActionForm dynaForm = (BaseActionForm) form;

    dynaForm.initialize(mapping);//from   ww  w . j a v  a 2 s  .c  o  m
    PropertyUtils.setProperty(dynaForm, "patientProperties", new PatientManagementInfo());

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.patient.action.PatientUpdateAction.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 Patient.
    // If there is a parameter present, we should bring up an existing
    // Patient 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 . ja  v a 2 s .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");

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

    String selectedPersonId = (String) dynaForm.get("selectedPersonId");

    List persons = new ArrayList();
    List genders = new ArrayList();

    if (dynaForm.get("persons") != null) {
        persons = (List) dynaForm.get("persons");
    } else {
        PersonDAO personDAO = new PersonDAOImpl();
        persons = personDAO.getAllPersons();
    }
    if (dynaForm.get("genders") != null) {
        genders = (List) dynaForm.get("genders");
    } else {
        GenderDAO genderDAO = new GenderDAOImpl();
        genders = genderDAO.getAllGenders();
    }

    Person person = null;
    // get the right person to update patient 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(patient, dynaForm);

    patient.setPerson(person);

    try {

        PatientDAO patientDAO = new PatientDAOImpl();

        if (!isNew) {
            // UPDATE

            patientDAO.updateData(patient);
            if (FWD_NEXT.equals(direction)) {
                List patients = patientDAO.getNextPatientRecord(patient.getId());
                if (patients != null && patients.size() > 0) {
                    patient = (Patient) patients.get(0);
                    patientDAO.getData(patient);
                    if (patients.size() < 2) {
                        // disable next button
                        request.setAttribute(NEXT_DISABLED, "true");
                    }
                    id = patient.getId();
                } else {
                    // disable next button
                    request.setAttribute(NEXT_DISABLED, "true");
                }
                forward = FWD_NEXT;
            }

            if (FWD_PREVIOUS.equals(direction)) {
                List patients = patientDAO.getPreviousPatientRecord(patient.getId());
                if (patients != null && patients.size() > 0) {
                    patient = (Patient) patients.get(0);
                    patientDAO.getData(patient);
                    if (patients.size() < 2) {
                        // disable previous button
                        request.setAttribute(PREVIOUS_DISABLED, "true");
                    }
                    id = patient.getId();
                } else {
                    // disable previous button
                    request.setAttribute(PREVIOUS_DISABLED, "true");
                }
                forward = FWD_PREVIOUS;
            }
        } else {
            // INSERT

            patientDAO.insertData(patient);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("PatientUpdateAction", "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, patient);

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

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

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

    }

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

}

From source file:us.mn.state.health.lims.person.action.PersonAction.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 Person.
    // If there is a parameter present, we should bring up an existing
    // Person to edit.

    String id = request.getParameter(ID);

    String forward = "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*/

    Person person = new Person();

    String hPhoneForDisplay = "";
    String wPhoneForDisplay = "";
    String cPhoneForDisplay = "";
    String faxForDisplay = "";

    String wPhoneExtForDisplay = "";

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

        person.setId(id);
        PersonDAO personDAO = new PersonDAOImpl();
        personDAO.getData(person);

        // format phone numbers for display
        String wPhone = person.getWorkPhone();
        wPhoneForDisplay = StringUtil.formatPhoneForDisplay(wPhone);
        wPhoneExtForDisplay = StringUtil.formatExtensionForDisplay(wPhone);

        String hPhone = person.getHomePhone();
        hPhoneForDisplay = StringUtil.formatPhoneForDisplay(hPhone);

        String cPhone = person.getCellPhone();
        cPhoneForDisplay = StringUtil.formatPhoneForDisplay(cPhone);

        String fax = person.getFax();
        faxForDisplay = StringUtil.formatPhoneForDisplay(fax);

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

        // do we need to enable next or previous?
        List persons = personDAO.getNextPersonRecord(person.getId());
        if (persons.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        persons = personDAO.getPreviousPersonRecord(person.getId());
        if (persons.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new person

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

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

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

    PropertyUtils.setProperty(dynaForm, "homePhone", hPhoneForDisplay);
    PropertyUtils.setProperty(dynaForm, "workPhone", wPhoneForDisplay);
    PropertyUtils.setProperty(dynaForm, "cellPhone", cPhoneForDisplay);
    PropertyUtils.setProperty(dynaForm, "fax", faxForDisplay);

    PropertyUtils.setProperty(dynaForm, "workPhoneExtension", wPhoneExtForDisplay);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.project.action.ProjectAction.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 Project.
    // If there is a parameter present, we should bring up an existing
    // Project 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.j a va2 s  .  co m

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

        project.setId(id);
        ProjectDAO projectDAO = new ProjectDAOImpl();
        projectDAO.getData(project);

        // initialize sysUserId
        if (project.getSystemUser() != null) {
            project.setSysUserId(project.getSystemUser().getId());
        }
        // initialize scriptlet
        if (project.getScriptlet() != null) {
            project.setScriptletName(project.getScriptlet().getScriptletName());
        }

        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 projects = projectDAO.getNextProjectRecord(project.getProjectName());
        if (projects.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        //bugzilla 1427 pass in name not id
        projects = projectDAO.getPreviousProjectRecord(project.getProjectName());
        if (projects.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button

    } else { // this is a new project
        // default started date to today's date
        Date today = Calendar.getInstance().getTime();
        Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE");

        String dateAsText = DateUtil.formatDateAsText(today, locale);

        project.setStartedDateForDisplay(dateAsText);

        // default isActive to 'Y'
        project.setIsActive("Y");

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

    }

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

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

    ProgramDAO programDAO = new ProgramDAOImpl();
    SystemUserDAO sysUserDAO = new SystemUserDAOImpl();

    List programs = programDAO.getAllPrograms();
    List sysUsers = sysUserDAO.getAllSystemUsers();

    PropertyUtils.setProperty(form, "programs", programs);
    PropertyUtils.setProperty(form, "sysUsers", sysUsers);

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

From source file:us.mn.state.health.lims.project.action.ProjectUpdateAction.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 Project.
    // If there is a parameter present, we should bring up an existing
    // Project 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;//w  w  w.j  a  v a2s  .c o m
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);
    try {
        errors = validateAll(request, errors, dynaForm);
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ProjectUpdateAction", "performAction()", e.toString());
        ActionError error = new ActionError("errors.ValidationException", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    }

    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);
    }

    List sysUsers = new ArrayList();
    List programs = new ArrayList();
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    if (dynaForm.get("sysUsers") != null) {
        sysUsers = (List) dynaForm.get("sysUsers");
    } else {
        SystemUserDAO sysUserDAO = new SystemUserDAOImpl();
        sysUsers = sysUserDAO.getAllSystemUsers();
    }
    if (dynaForm.get("programs") != null) {
        programs = (List) dynaForm.get("programs");
    } else {
        ProgramDAO programDAO = new ProgramDAOImpl();
        programs = programDAO.getAllPrograms();
    }

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

    String sysUserId = (String) dynaForm.get("sysUserId");

    SystemUser sysUser = null;

    for (int i = 0; i < sysUsers.size(); i++) {
        SystemUser su = (SystemUser) sysUsers.get(i);
        if (su.getId().equals(sysUserId)) {
            sysUser = su;
            break;
        }
    }

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

    Scriptlet scriptlet = new Scriptlet();
    String scriptletName = (String) dynaForm.get("scriptletName");
    scriptlet.setScriptletName(scriptletName);

    ScriptletDAO scriptletDAO = new ScriptletDAOImpl();
    Scriptlet scr = scriptletDAO.getScriptletByName(scriptlet);

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

    project.setSystemUser(sysUser);
    project.setScriptlet(scr);
    // there is no specification for sticker req flag, but it can't be null
    // so default to N
    if (project.getStickerReqFlag() == null) {
        project.setStickerReqFlag(NO);
    }

    try {

        ProjectDAO projectDAO = new ProjectDAOImpl();

        if (!isNew) {
            // UPDATE
            projectDAO.updateData(project);
        } else {
            // INSERT
            projectDAO.insertData(project);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ProjectUpdateAction", "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 {
            //bugzilla 1482
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                java.util.Locale locale = (java.util.Locale) request.getSession()
                        .getAttribute("org.apache.struts.action.LOCALE");
                //bugzilla 2438
                String messageKey = "project.projectNameOrLocalAbbrev";
                String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
                error = new ActionError("errors.DuplicateRecord.activate", 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);
        // in case of database exception don't allow another save without
        // cancel first
        //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, project);

    PropertyUtils.setProperty(dynaForm, "programs", programs);
    PropertyUtils.setProperty(dynaForm, "sysUsers", sysUsers);

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

    if (project.getId() != null && !project.getId().equals("0")) {
        request.setAttribute(ID, project.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.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);//ww w. ja v a2 s  .  c  o m

    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);
}