Saleforce之actionFunction和setTimeout 定时调用

来源:互联网 发布:四川大学网络本科 编辑:程序博客网 时间:2024/05/18 11:48

ViualForce

<apex:page controller="exampleCon"><script type="text/javascript">var myVar;function myFunction() {    myVar = setTimeout(alertFunc, 3000);    methodOneInJavascript('no');}function alertFunc() {    //alert("Hello!");    myFunction();}</script>    <apex:form >        <!-- Define the JavaScript function sayHello-->        <apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/>    </apex:form>    <apex:outputPanel id="out">    <apex:outputText value="Hello "/>    <apex:actionStatus startText="requesting..." id="myStatus">        <apex:facet name="stop">{!username}</apex:facet>    </apex:actionStatus>    </apex:outputPanel>                <!-- Call the sayHello JavaScript function using a script element-->    <script>window.setTimeout(sayHello,2000)</script>                <p><apex:outputText value="Clicked? {!state}" id="showstate" /></p>                 <!-- Add the onclick event listener to a panel. When clicked, the panel triggers    the methodOneInJavascript actionFunction with a param -->    <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn" >         Click Me     </apex:outputPanel>    <apex:form >    <apex:commandButton >    <apex:commandButton action="{!methodOne}" value="+" id="pulsButton" style="width:40px; font-weight:bold" onComplete="return myFunction();"/>    </apex:commandButton>    <apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="showstate">        <apex:param name="firstParam" assignTo="{!state}" value="" />    </apex:actionFunction>    </apex:form></apex:page>


Apex

public with sharing class exampleCon {    String uname;    public String getUsername() {        return uname;    }                public PageReference sayHello() {        uname = UserInfo.getName();        return null;    }                public void setState(String n) {        state = n;    }                public String getState() {        return state;    }          public PageReference methodOne() {    string par = ApexPages.currentPage().getParameters().get('firstParam');    state = par + 'ctrl';        return null;    }                private String state = 'no';}

Visualforce Pageにapex:paramタグの使用方法まとめ

https://www.xgeek.net/ja/salesforce/the-usage-of-apexparam-in-visualforce-page/

0 0