0

我有以下执行代码,但它给出了一些与 ajax 请求相关的问题。

actionListener 按钮点击调用

<a4j:commandButton value="Submit" alt="OligoWalk" styleClass="common_button" onclick="createNewLog();showProgressLayer();" oncomplete="parent.document.getElementById('resultFrm').src ='#{MyResearchView.resultToShow}';parent.reRenderLogSection();" actionListener="#{MyResearchView.executeTool}">        <f:attribute name="toolClass" value="com.sequerome.service.impl.tools.Oligowalk" />
<f:attribute name="toolId" value="#{ToolCustomeFormView.toolId}" />   <f:attribute name="toolName" value="#{ToolCustomeFormView.toolName}" />                    <f:attribute name="inputParamFile" value="#{ToolCustomeFormView.inputParamFile}" />
<f:attribute name="paramMap" value="#{ToolCustomeFormView.toolParamBean.paramMap}" />
</a4j:commandButton>

A4j:js函数

<a4j:jsFunction name="createNewLog"
   actionListener="#{MyResearchView.createNewLogEntry}"
   oncomplete="parent.reRenderLogSection();executeTool();">
   <f:attribute name="toolId" value="#{ToolCustomeFormView.toolId}" />
   <f:attribute name="toolName" value="#{ToolCustomeFormView.toolName}"/></a4j:jsFunction>
  1. createNewLog() 函数必须先完成
  2. executeTool() 函数必须在那之后完成。

目前它以相同的方式调用,但 createNewLog() 函数的一半首先执行,然后它转到 executeTool() 函数。在这里它需要一些代码来执行,然后它再次转向 createNewlog() 函数。在此之后执行 createNewLog(),然后再次执行 executeTool()。

<a4j:commandButton value="Submit" alt="OligoWalk" styleClass="common_button" onclick="createNewLog();showProgressLayer();" oncomplete="parent.document.getElementById('resultFrm').src ='#{MyResearchView.resultToShow}';parent.reRenderLogSection();" actionListener="#{MyResearchView.executeTool}">        <f:attribute name="toolClass" value="com.sequerome.service.impl.tools.Oligowalk" />
<f:attribute name="toolId" value="#{ToolCustomeFormView.toolId}" />   <f:attribute name="toolName" value="#{ToolCustomeFormView.toolName}" />                    <f:attribute name="inputParamFile" value="#{ToolCustomeFormView.inputParamFile}" />
<f:attribute name="paramMap" value="#{ToolCustomeFormView.toolParamBean.paramMap}" />
</a4j:commandButton>

<a4j:jsFunction name="createNewLog"
   actionListener="#{MyResearchView.createNewLogEntry}"
   oncomplete="parent.reRenderLogSection();executeTool();">
   <f:attribute name="toolId" value="#{ToolCustomeFormView.toolId}" />
   <f:attribute name="toolName" value="#{ToolCustomeFormView.toolName}"/></a4j:jsFunction>
4

2 回答 2

0

症状可能是 a4j:function 是异步函数的结果。我相信幕后发生的事情是:

  • 创建新日志();
    • 调用 a4j:function
    • a4j:function 发送请求
    • a4j:function 返回(请求仍在发生)
  • showProgressLayer();
    • 调用 a4j:function
    • a4j:fucntion 发送请求(createNewLog 请求现在恰好完成了一半)
    • a4j:function 返回(请求仍在发生)
  • actionListener 请求被触发
    • 请求在服务器上执行,可能在 createNewLog 和 showProgressLayer 仍在运行时

一种解决方案是在客户端添加队列并在服务器端添加同步

于 2011-08-10T18:04:30.280 回答
0

不知道你在这里的目标是什么。一些代码会有所帮助。a4j:jsFunction 有一个名为 oncomplete 的 javascript 事件。我想一种方法是在收到此事件时调用其他 js 函数...

于 2010-12-04T13:34:55.190 回答