【问题标题】:Calling another a4j:jsFunction in an a4j:jsFunction oncomplete event在 a4j:jsFunction oncomplete 事件中调用另一个 a4j:jsFunction
【发布时间】:2011-02-23 04:30:51
【问题描述】:

我定义了一些 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}”。我该如何解决这个问题?

【问题讨论】:

  • 你检查了javascript控制台(在Firefox中)

标签: javascript jsf richfaces ajax4jsf


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-09-11
    • 2014-04-25
    • 1970-01-01
    • 2013-05-01
    • 2013-02-27
    • 2015-12-11
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    相关资源
    最近更新 更多