在 a4j:jsFunction oncomplete 事件中调用另一个 a4j:jsFunction

发布于 2024-09-03 02:30:28 字数 585 浏览 2 评论 0原文

我定义了一些java脚本函数,它将使用a4j:jsFunction调用后端函数。例如:

<a4j:jsFunction name="function1"  action="#{Bean1.action1}" oncomplete="function2();"/> 

<a4j:jsFunction name="function2"  action="#{Bean1.action2}" oncomplete="SomeJSFunc2();"/> 

然后在a4j:commandButton中,我设置onclick属性来调用我定义的函数,如下所示:

<a4j:commandButton onclick="function1" oncomplete="SomeJSFunc3();"> 

当单击a4j:commandButton时, #{Bean1.action1} 运行。#{Bean1.action1} 返回后,(a4j:jsFunction name="function1") 的 oncomplete 事件 无法调用“#{Bean1.action2}”。我该如何解决这个问题?

I define some java script function which will call the back-end functions using a4j:jsFunction.For example :

<a4j:jsFunction name="function1"  action="#{Bean1.action1}" oncomplete="function2();"/> 

<a4j:jsFunction name="function2"  action="#{Bean1.action2}" oncomplete="SomeJSFunc2();"/> 

Then in the a4j:commandButton , I set the onclick property to call my defined function like it:

<a4j:commandButton onclick="function1" oncomplete="SomeJSFunc3();"> 

When the a4j:commandButton is clicked , #{Bean1.action1} is run .After the #{Bean1.action1} returned , the oncomplete event of the (a4j:jsFunction name="function1")
cannot invoke the "#{Bean1.action2}" .How can I solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征﹌骨岁月お 2024-09-10 02:30:28

jsf 页面:

  <a4j:commandButton
      oncomplete="switchTab(1);"
      action="#{backBean.actionSwitchTab4}"
      value="#{res['button_forward']}c" styleClass="button" />
  <a4j:jsFunction id="testFunc" name="switchTab"
      action="#{backBean.actionSwitchTab}"
      oncomplete="switchTab2(6);">
      <a4j:actionparam name="tabIndex" assignTo="#{backBean.tabIndexTl}" />
  </a4j:jsFunction>
  <a4j:jsFunction id="testFunc2" name="switchTab2"
      action="#{backBean.actionSwitchTab2}"
      oncomplete="showConfirmPrompt();">
      <a4j:actionparam name="tabIndex" assignTo="#{backBean.tabIndexTi}" />
  </a4j:jsFunction>
  <a4j:jsFunction id="testFunc3" name="switchTab3"
      action="#{backBean.actionSwitchTab3}"
      oncomplete="alert('this is the end');">
      <a4j:actionparam name="tabIndex" assignTo="#{backBean.tabIndexTs}"/>
  </a4j:jsFunction>
  <script language="javascript" type="text/javascript">
   <!--
   function showConfirmPrompt() {
       if(confirm('Activate other a4j:jsFunction function')) {
           switchTab3('test');
           return true;
       }
       return false;
   }
   //-->
  </script>

backbean(java):

 private Integer tabIndexTi; // + GETTER, SETTER
 private String tabIndexTs;  // + GETTER, SETTER
 private Long tabIndexTl;    // + GETTER, SETTER

 public Object actionSwitchTab() {   
   System.out.println("  >>>>> actionSwitchTab start; tabIndexTl: " + tabIndexTl);   
   try {    
     Thread.sleep(2000);   
   } catch (InterruptedException ex) {    
     ex.printStackTrace();   
   }   
   System.out.println("  >>>>> actionSwitchTab end");   
   return null;  
  }

  public Object actionSwitchTab2() {   
   System.out.println("  >>>>> actionSwitchTab2 start; tabIndexTi: " + tabIndexTi);   
   try {    
     Thread.sleep(500);   
   } catch (InterruptedException ex) {    
     ex.printStackTrace();   
   }   
   System.out.println("  >>>>> actionSwitchTab2 end");   
   return null; 
  }

  public Object actionSwitchTab3() {   
    System.out.println("  >>>>> actionSwitchTab3 start; tabIndexTs: " + tabIndexTs);   
    try {    
      Thread.sleep(3000);   
    } catch (InterruptedException ex) {    
      ex.printStackTrace();   
    }   
    System.out.println("  >>>>> actionSwitchTab3 end");   
    return null; 
  }

  public Object actionSwitchTab4() {   
    System.out.println("  >>>>> actionSwitchTab4");   
    return null;  
  }

jsf page:

  <a4j:commandButton
      oncomplete="switchTab(1);"
      action="#{backBean.actionSwitchTab4}"
      value="#{res['button_forward']}c" styleClass="button" />
  <a4j:jsFunction id="testFunc" name="switchTab"
      action="#{backBean.actionSwitchTab}"
      oncomplete="switchTab2(6);">
      <a4j:actionparam name="tabIndex" assignTo="#{backBean.tabIndexTl}" />
  </a4j:jsFunction>
  <a4j:jsFunction id="testFunc2" name="switchTab2"
      action="#{backBean.actionSwitchTab2}"
      oncomplete="showConfirmPrompt();">
      <a4j:actionparam name="tabIndex" assignTo="#{backBean.tabIndexTi}" />
  </a4j:jsFunction>
  <a4j:jsFunction id="testFunc3" name="switchTab3"
      action="#{backBean.actionSwitchTab3}"
      oncomplete="alert('this is the end');">
      <a4j:actionparam name="tabIndex" assignTo="#{backBean.tabIndexTs}"/>
  </a4j:jsFunction>
  <script language="javascript" type="text/javascript">
   <!--
   function showConfirmPrompt() {
       if(confirm('Activate other a4j:jsFunction function')) {
           switchTab3('test');
           return true;
       }
       return false;
   }
   //-->
  </script>

backbean(java):

 private Integer tabIndexTi; // + GETTER, SETTER
 private String tabIndexTs;  // + GETTER, SETTER
 private Long tabIndexTl;    // + GETTER, SETTER

 public Object actionSwitchTab() {   
   System.out.println("  >>>>> actionSwitchTab start; tabIndexTl: " + tabIndexTl);   
   try {    
     Thread.sleep(2000);   
   } catch (InterruptedException ex) {    
     ex.printStackTrace();   
   }   
   System.out.println("  >>>>> actionSwitchTab end");   
   return null;  
  }

  public Object actionSwitchTab2() {   
   System.out.println("  >>>>> actionSwitchTab2 start; tabIndexTi: " + tabIndexTi);   
   try {    
     Thread.sleep(500);   
   } catch (InterruptedException ex) {    
     ex.printStackTrace();   
   }   
   System.out.println("  >>>>> actionSwitchTab2 end");   
   return null; 
  }

  public Object actionSwitchTab3() {   
    System.out.println("  >>>>> actionSwitchTab3 start; tabIndexTs: " + tabIndexTs);   
    try {    
      Thread.sleep(3000);   
    } catch (InterruptedException ex) {    
      ex.printStackTrace();   
    }   
    System.out.println("  >>>>> actionSwitchTab3 end");   
    return null; 
  }

  public Object actionSwitchTab4() {   
    System.out.println("  >>>>> actionSwitchTab4");   
    return null;  
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文