简体   繁体   English

如何从 Strutus 1 中的单个表单调用多个操作?

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

Need to call multiple action, from a single JSP.需要从单个 JSP 调用多个操作。 I have tried few ways but it's not per standard, help me out to call multiple action without using ajax .我尝试了几种方法,但不是每个标准,请帮助我在不使用 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还有如何使用 windows.href 调用另一个动作

NOTE: parameter should be passed through URL, Please advice注意:参数应通过 URL 传递,请指教

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?这听起来更像是一个 XY 问题:你真正想要的最终结果是什么?

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.在显示的(凌乱!)代码片段中,您没有调用两个操作,而是根据是否存在剧集 ID 调用两个操作之一,因此您甚至不清楚您在问什么。

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).通过拆分 JSP 来提取业务逻辑,使用不同的 JSP(和片段或模板)来拆分各种用例,并开始在后端添加 API/JSON 端点并至少使用 Ajax,您会得到更好的服务,或者开始引入组件(React、Vue 等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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