Calling another a4j:jsFunction in an a4j:jsFunction oncomplete event

故事扮演 提交于 2019-12-24 19:13:33

问题


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?


回答1:


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;  
  }


来源:https://stackoverflow.com/questions/2896283/calling-another-a4jjsfunction-in-an-a4jjsfunction-oncomplete-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!