What is the best way to trigger multiple actions from a single form in Struts 1?

Seeking assistance on how to call multiple actions from a single JSP without using ajax. I have attempted various methods, but they don't meet the standards. Can you provide guidance on calling multiple actions without ajax?

<html:form action="inspathNew" name="personInsuranceForm" method="post" scope="request">
    <a id="addPatientButton" class="ovalbutton" href="javascript:void(0);"> 
      <span>
          <html:button property="addPatient" onclick="javascript:AddPatient();" /> 
     </span>
    </a> 
  </html>

function AddPatient() {
    var jobIdVal = document.forms[0].jobId.value;
    var batchId = document.forms[0].batchId.value;
    var batchCode = document.forms[0].batchCode.value;
    var batchCount = document.forms[0].batchCount.value;
    var epiCount = document.forms[0].epiCount.value;
    var docNum = document.forms[0].docNum.value;
    var entryDate = document.forms[0].entryDate.value;
    var admitDate = document.forms[0].admitDate.value;
    var disDate = document.forms[0].disDate.value;
    var epiMode = document.forms[0].epiMode.value;
    var episodeId = document.forms[0].episodeIdVal.value;
    var epiCntVal = document.forms[0].epiCntVal.value;
    var epiDRN = document.forms[0].epiDRN.value;
    var batchScanStatus = document.forms[0].batchScanStatus.value;
    // bug #1569
    var patLastName = document.forms[0].plname.value.toUpperCase();
    var patFirstName = document.forms[0].pfname.value.toUpperCase();
    var patSSN = document.forms[0].pssn.value;
    var PatMrn = document.forms[0].mrn.value;
    //bug 2304 c#90
<%  String emrEpisodeId = request.getParameter("emrEpisodeId");
    if (emrEpisodeId != null && emrEpisodeId.length() > 0) {%>
        // to create new person from emrEpisode detail
        window.location.href = "<%=request.getContextPath()%>/action/personInfoNew?action=<%=com.abc.dataentry.person.action.PersonAction.ACTION_CREATE_PERSON_FROM_EMR%>&<%=com.abc.dataentry.person.action.PersonAction.PARAM_EMR_EPISODE_ID%>=" + <%=emrEpisodeId%> + "&<%=com.abc.dataentry.person.action.PersonAction.PARAM_JOB_ID%>="+ document.forms[0]['jobId'].value+"&patFirstName="+patFirstName+"&patLastName="+patLastName+"&patSSN="+patSSN;
<%  } else {%> 
        var url = "<%=request.getContextPath()%>/action/personInfoNew?action=newPatient&episodeId=<%=request.getParameter("episodeId")%>&name=<%=request.getParameter("name")%>&patientId=<%=request.getParameter("patientId")%>&jobId="+jobIdVal+"&batchId="+batchId+"&batchCode="+batchCode+"&batchCount="+batchCount+"&epiCount="+epiCount+"&epiMode="+epiMode+"&episodeIdVal="+episodeId+"&epiCntVal="+epiCntVal;
        //bug # 2598 - view only person info
        var viewMode = "<%=IConstants.PARAM_VIEWMODE%>=<%=IConstants.MODE_VIEWONLY%>";
        if(${showPageEditableMode}){
            viewMode = "<%=IConstants.PARAM_VIEWMODE%>=<%=IConstants.MODE_EDITABLE%>";
        }
        window.location.href="<%=request.getContextPath()%>/action/personInfoNew?"+viewMode+"&action=newPatient&episodeId=<%=request.getParameter("episodeId")%>&name=<%=request.getParameter("name")%>&patientId=<%=request.getParameter("patientId")%>&jobId="+jobIdVal+"&batchId="+batchId+"&batchCode="+batchCode+"&batchCount="+batchCount+"&epiCount="+epiCount+"&docNum="+docNum+"&entryDate="+entryDate+"&admitDate="+admitDate+"&disDate="+disDate+"&epiMode="+epiMode+"&episodeIdVal="+episodeId+"&epiCntVal="+epiCntVal+"&batchScanStatus="+batchScanStatus+"&epiDRN="+epiDRN+"&patFirstName="+patFirstName+"&patLastName="+patLastName+"&patSSN="+patSSN+"&mrnValue="+PatMrn;
<%  }%>
}

Additionally, looking for information on how to call another action using windows.href.

NOTE: Parameters should be passed through URL. Please advise accordingly.

Answer №1

There's a better way to handle this situation because web browsers don't work like that.

If you attempt a form submission and then leave the page, the outcome is uncertain; the submission may have begun or not at all.

This seems to be more of an XY problem: what is your ultimate goal?

If you simply want to go through the processing steps of multiple actions upon form submission, it is advisable to extract the logic from the actions themselves and create a new endpoint that calls the logic for each action.

In the provided code snippet, it appears that you are not calling two actions but rather one depending on the presence of an episode ID, making the question unclear.

On a separate note, avoid cramming too much logic into the view layer as it can lead to issues, especially in a legacy system with outdated frameworks and code style/naming conventions.

To avoid future complications, consider breaking up JSPs to extract business logic, utilizing different JSPs and templates for various use-cases, implementing API/JSON endpoints on the backend, incorporating Ajax or components like React or Vue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Does the TS keyof typeof <Object> rule prohibit the assignment of object.keys(<Object>)?

I'm having trouble understanding the issue with this code snippet. Here is the piece of code in question: export type SportsTypes = keyof typeof SportsIcons export const sports: SportsTypes[] = Object.keys(SportsIcons); The problem arises when I at ...

How to send emails with attachments using WordPress?

Looking for assistance in sending emails with attachments using Wordpress. I am struggling and believe there might be something missing in my code. Any help would be greatly appreciated! :) Below is the code spread across two files: Name (required)<b ...

Retrieve the information sent back by AngularJS and pass it to a JavaScript function

I am working on a form using AngularJS to create a new object, which is returned as "marker." $scope.createMarker = function() { $http.post('/markers/create', $scope.marker) .success(function(data) { }) .error(funct ...

Barba.js Revolutionizes Page Reloading for Initial Links

On my Wordpress site, I am using Barba js v.2 for page transitions. However, I have encountered an issue where I need to click on a link twice in order to successfully change the page and make the transition work. Interestingly, the first time I click on t ...

Prevent the need to go through the keycloak callback process each time the page is

I have integrated keycloak as an identity provider into my React application. I successfully added the keycloak react dependency via npm. Below are the versions of the keycloak react npm modules on which my application depends : "@react-keycloak/web ...

Ways to resolve the issue of data not displaying on the page, even though it appears in the

I am attempting to upload an image that has been converted to a URL using Ajax. The issue I am facing is that $image = $_POST['imgData']; does not display anything, but when I check the developer tools in the network preview, the data can be seen ...

Prevent any pop-up windows from appearing when a specific link is clicked

On my website, I have implemented popup advertising where ads open when clicked inside the body. However, I am looking to disable popups when a link with the class donot is clicked. Currently, when the donot link is clicked, a popup opens and the link doe ...

Troubleshooting JavaScript for Sidebar Disappearance due to marginRight and display CSS Issue

I need to adjust the layout of my website so that the sidebar disappears when the window is resized below a certain width, and then reappears when the window is expanded. Here is the HTML code: <style type="text/css"> #sidebar{ width:290 ...

Preventing scrolling in jQuery UI Draggable when using flexbox

In my project, I am looking to organize a container using jQuery UI draggable/droppable feature. Since the elements in my list are arranged in a straight horizontal line, I have utilized display: flex. This arrangement works well when adding new items to ...

Guide on converting AS3 to HTML5 while incorporating external AS filesAlternatively: Steps for transforming AS

I've been given the challenging task of transforming a large and complex Flash project into html5 and javaScript. The main stumbling block I'm facing is its heavy reliance on external .as files, leaving me uncertain about the best approach. Most ...

The Bootstrap modal-backdrop dilemma requiring JavaScript intervention

I am encountering some problems with the Bootstrap modal. When I try to open a modal, everything looks good, but when I close it, the screen turns completely black. Upon closer inspection, I found that every time I click on the X to close the modal, there ...

Implementing a persistent header on a WordPress site with Beaver Builder

My website URL is: . I have chosen to use beaver builder for building and designing my website. I am in need of a fixed header that can display over the top of the header image. Here is the code snippet that I currently have: <div id="header">html ...

Encountered an error when trying to access the 'modules' property of undefined in the /node_modules/bindings/bindings.js file while working with electron and setting up

1. npm install -g node-gyp 2. npm install serialport -S 3. npm install electron-rebuild -D 4. ./node_modules/.bin/electron-rebuild.cmd and after that, the rebuild process is completed. When I execute the command: npm run electron:serve, I encounter an ...

I am confused as to why my function is selecting all the checkboxes when it should only be selecting one

I am facing an issue while creating a list with checkboxes in reactJS. Whenever I click on a single checkbox, all the checkboxes get selected instead of just the one that was clicked. How can I resolve this problem? const checkHandler = () => { if ( ...

Trouble with clicking buttons in Java and Selenium web scraping

Hey everyone, Currently, I'm working on a Java Selenium script that automates clicking and filling forms for me. I've written a line of code that's causing me some trouble. The intention is to click on a button, but it's not happening ...

Angular Js powered admin control panel

Explore the SB Admin Angular by Start Angular My current project involves setting up an admin dashboard on a Windows system. However, I have encountered some issues during the installation process using npm install An error message can be found here ...

Leverage AJAX to fetch data from the database

I've been exploring different methods to automate the process of copying a database table. While replication was suggested as an option, I found it challenging to set up properly. Therefore, I have decided to use a script approach instead. In an effo ...

Determine if the object's value is present

My current JavaScript setup looks like this: var NAMES = []; function INFO(id,first,middle,last){ var newMap = {}; newMap[id] = [first, middle, last]; return newMap ; } Next, I have the following code block: for (var j = 0; j < NUMBER.leng ...

While it includes a new section, it fails to refresh the navbar

Upon clicking the button to add a new section, the section gets added successfully. However, the navbar does not get updated as expected. It should dynamically update the navbar to display both the existing sections and the new section added using JavaScri ...

Navigating an array to link values to anchor tags

I'm struggling with an array that contains image file names ["1352.jpg", "1353.jpg", "1354"]. My goal is to loop through this array and generate anchor links for each item separated by commas. I've attempted the following code snippet, but it&apo ...