Saleforce之actionFunction和setTimeout 定时调用

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 οnclick="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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值