在Component-Visualforce中从javascript调用控制器方法

时间:2014-08-04 06:52:26

标签: javascript controller components visualforce apex

<apex:component>
 <apex:attribute name="l" description="l" type="double" assignTo="{!Received_L}"/>
  <apex:attribute name="varLng" description="t" type="double" assignTo="{!Received_T}"/>  
   //***** from here i want to call assignLocation()--------

</apex:component>

我的组件控制器

public class myController {
     public double Recieved_L{get;set;}
     public double Recieved_T{get;set;}

     public myController(){} //constructor        

    public PageReference assignLocation() {
        l=Recieved_L;
        t=Recieved_T;
        return null;
    }

我不想在构造函数中调用此方法,我想在页面加载后调用myMethod()

1 个答案:

答案 0 :(得分:0)

从javascript调用Apex控制器方法的最佳方法是使用
https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

<apex:component>
 <apex:attribute name="l" description="l" type="double" assignTo="{!Received_L}"/>
  <apex:attribute name="varLng" description="t" type="double" assignTo="{!Received_T}"/>  
   //***** from here i want to call assignLocation()--------

  <apex:actionFunction name='myMethod' action='{!assignLocation}' />
</apex:component>

您需要一个javascript代码才能从您的组件或visualforce页面中的组件外部调用此操作功能。有关如何实现此目的的更深入信息,请查看链接。