简体   繁体   中英

how to call multiple action from a single form in Strutus 1?

Need to call multiple action, from a single JSP. I have tried few ways but it's not per standard, help me out to call multiple action without using 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;
<%  }%>
}

also how to call the another action using windows.href

NOTE: parameter should be passed through URL, Please advice

You don't. That's not how web browsers work.

If you start a form submission then navigate away from the page the end result is somewhat indeterminate; the submission may have started, it may not have.

This sounds more like an XY problem: what's the end result you're actually after?

If you just need to run through the processing steps of multiple actions on a form submission then that logic should be extracted from the actions (which should already be how it's done), and you create a new endpoint (if you still need the originals) that calls the logic of each of the two current actions.

In the (messy!) code snippet shown you're not calling two actions, you're calling one of two actions based on whether or not there's episode ID, so it's not clear what you're even asking.

Unrelated: you're shoving too much logic into the view layer, and the code shows that you've already suffered because of this. It will only get worse. It's also clear that this is a legacy system, from both the framework used and the code style/naming conventions.

You are starting down a path to sadness. You would be better served by breaking up JSPs to extract business logic, using different JSPs (and fragments or templating) to break up various use-cases, and starting to add API/JSON endpoints on the back end and using Ajax at the least, or start bringing in components (React, Vue, whatever).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM