Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:08:44+00:00 2026-06-11T02:08:44+00:00

I’m trying to refactor this code to be cleaner and use better OOP practices.

  • 0

I’m trying to refactor this code to be cleaner and use better OOP practices. This method takes a bunch radio/checkbox and textbox responses and updates them in a database table and then updates the Checklist itself in another database table.

I feel this method is trying to do to much. But I need to determine a few things that other methods and classes use, such as if a deficiency exists (radio value = 2), whether to advance the workFlow (advanceWorkflow boolean determined in processUpdateCheckbox), who to email next based on the status of the currentActionItem and the advanceWorkflow boolean, as well as persist the responses.

The setFormFeedback doesn’t belong here either because the method is being called from another Servlet that is handling the form data and this message is lost.

Any help at refactoring this greatly appreciated.

public ChecklistInstance updateYesNoNAChecklistTogles(HttpServletRequest request, ChecklistInstance ci) throws DAOException {
    String work_item_class_id = request.getParameter("work_item_class_id");
    String work_action_class_id = request.getParameter("work_action_class_id");

    String paramName;
    String attribute_id;
    String radioValue;
    String textValue;
    String strStatus = "1";
    String strStoredNo = "";
    Date dateNow = new Date();

    YesNoNAAnswerDAO ynnDao = new YesNoNAAnswerDAO();
    ChecklistInstanceDAO ciDao = new ChecklistInstanceDAO();

    WorkflowInstanceWorkItemAction currentActionItem = new WorkflowInstanceWorkItemAction();
    currentActionItem.setWork_item_class_id(work_item_class_id);
    currentActionItem.setWork_action_class_id(work_action_class_id);

// Put the form check list responses into a list
    List answer_attribute_list = new ArrayList();

    java.util.Enumeration enum2 = request.getParameterNames();
        while (enum2.hasMoreElements()) {
            paramName = (String) enum2.nextElement();
            boolean isNewQ = paramName.startsWith("qID_");

            if (isNewQ) {
                attribute_id = paramName.replaceAll("qID_", "");
                YesNoNAAnswer clr = new YesNoNAAnswer();

                if (request.getParameter("radio_" + attribute_id) != null) {
                    radioValue = request.getParameter("radio_" + attribute_id);
                } else {
                    radioValue = "0";
                }

                if (request.getParameter("textbox_" + attribute_id) != null) {
                    textValue = request.getParameter("textbox_" + attribute_id);
                } else {
                    textValue = "";
                }

                if (request.getParameter("check_" + attribute_id) != null) {
                    radioValue = request.getParameter("check_" + attribute_id);
                } else {
                    // checkValue = "";
                }

                if ("0".equals(radioValue) || "2".equals(radioValue)) {
                    strStatus = "0";
                }

                strStoredNo = request.getParameter("stored_" + attribute_id);
                if ("2".equals(radioValue) && !"yes".equals(strStoredNo)) {
                    deficiencyFound = true;
                }

                clr.setWorkflow_instance_id(ci.getWorkflow_instance_id());
                clr.setWfi_work_item_action_id(ci.getWfi_work_item_action_id());
                clr.setFail_reason(textValue);
                clr.setAttribute_id(attribute_id);
                clr.setToggle_value(radioValue);
                answer_attribute_list.add(clr);
            }
        }

        ci.setChecklist_state(strStatus);
        ci.setLast_update(dateNow);
        ci.setAdditional_info(FormUtil.getFieldValue(request, FIELD_ADDITIONAL_INFO));

        processUpdateCheckbox(request, ci, currentActionItem);

            // Update the base check list
            ciDao.updateInstance(ci, authenticatedUser);

            // Update the check list question responses
            ynnDao.updateToggles(answer_attribute_list, authenticatedUser);

            // update the work flow
            WorkflowInstanceDAO wfiDao = new WorkflowInstanceDAO();
            WorkflowInstanceForm wfiForm = new WorkflowInstanceForm(wfiDao, authenticatedUser);
            WorkflowInstance wfi = (WorkflowInstance) wfiForm.view(ci.getWorkflow_instance_id(), authenticatedUser);
            wfiForm.updateWorkFlowInstance(wfi, currentActionItem);

            setFormFeedback("You have successfully updated the checklist.");
            triggerUpdateEmail(request, ci, wfi, currentActionItem);

    return ci;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:08:45+00:00Added an answer on June 11, 2026 at 2:08 am

    First things first : you’re doing Object-Oriented programming, not procedural programming, that’s why you should think before hand which class should take which responsibilities.

    So, what are the responsiblities here ? We can list the following tasks that must be done independently :

    • validation of user input data : check the validity (range of values, invalid values, security concerns(injection protection)…) of values provided by your client through HTTP.
    • a controller that will only contains a list of calls to domain model methods.
    • a domain model : a set of classes representing your business data and offering manipulation methods.
    • a mean to persist your domain model : to a database, to XML files…

    Don’t forget to manage a transaction (if needed) from the start to the end of all processing.

    Remove useless dependencies : Your domain model should not know about HTTP and from where data is coming from.
    Your controller should not know how data is persisted.

    Don’t reinvent the wheel : use a MVC framework like Struts 2 for example for your validation and controller needs. Use a framework for persistence like hibernate/JPA.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.