Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Salesforce apex:visualforce组件中的commandButton不调用控制器方法_Salesforce_Apex Code_Visualforce - Fatal编程技术网

Salesforce apex:visualforce组件中的commandButton不调用控制器方法

Salesforce apex:visualforce组件中的commandButton不调用控制器方法,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我在visualforce组件中有一个commandButton。预期的行为是调用控制器方法。页面已刷新,但未调用commandButton{!performUnlinkContact}中注册的方法。奇怪的是,如果我将按钮放在基本visualforce页面上,它会按预期调用控制器方法——但在组件中,它不会 以下是我的组件: <apex:component > <apex:attribute name="rk" description="RK Base Contact D

我在visualforce组件中有一个commandButton。预期的行为是调用控制器方法。页面已刷新,但未调用commandButton
{!performUnlinkContact}
中注册的方法。奇怪的是,如果我将按钮放在基本visualforce页面上,它会按预期调用控制器方法——但在组件中,它不会

以下是我的组件:

<apex:component >
    <apex:attribute name="rk" description="RK Base Contact Data"  type="Object" required="true"/>

    <div class="unlinkBox">
        <div class="unlinkHeader">
            <div class="unlinkHeaderLeft">Wrong Contact?</div>
            <div class="unlinkHeaderRight"><a href=""  onclick="return hideUnlinkPanel()"><apex:image style="cursor: pointer;" value="{!$Resource.x}" alt="Close Panel" /></a></div>
        </div>
        <div class="unlinkBody">
            <div class="unlinkBodyLeft">
                Click Yes if the Contact displayed is incorrect.<br/><br/>You will be given the opportunity to link to a different Contact.
            </div>
            <div class="unlinkBodyRight">
                <apex:outputpanel id="callMethod">
                    <apex:commandbutton value="Yes, this is the wrong contact" action="{!performUnlinkContact}" rerender="" status="myDisplayStatus" />&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="return hideUnlinkPanel()" style="color:blue;cursor:pointer;text-decoration:underline">No</a>
                </apex:outputpanel>
                <apex:actionStatus id="myDisplayStatus"  startText="(performing Contact Unlink...)"  stopText=""/>
            </div>
        </div>
    </div>
</apex:component>
    <input type="button" value="Yes, this is the wrong contact" onclick="doUnlink();" />

我确信我一定是做错了什么,因为我是salesforce的新手,还在学习,但在搜索如何解决此问题时,我找不到任何相关问题。提前感谢您的帮助。

我认为
rerender=”“
不是执行伪rerender命令的方法。我会尝试使用
rerender=“none”

感谢您的回复-为了解决这个问题,我在基本页面添加了一个actionFunction,然后通过按钮的onclick事件在组件中调用这个函数:

基本页中的代码:

    <apex:actionFunction name="doUnlink" action="{!performUnlinkContact}" rerender="refresh" status="myStatus"/>

在组件中调用函数的代码:

<apex:component >
    <apex:attribute name="rk" description="RK Base Contact Data"  type="Object" required="true"/>

    <div class="unlinkBox">
        <div class="unlinkHeader">
            <div class="unlinkHeaderLeft">Wrong Contact?</div>
            <div class="unlinkHeaderRight"><a href=""  onclick="return hideUnlinkPanel()"><apex:image style="cursor: pointer;" value="{!$Resource.x}" alt="Close Panel" /></a></div>
        </div>
        <div class="unlinkBody">
            <div class="unlinkBodyLeft">
                Click Yes if the Contact displayed is incorrect.<br/><br/>You will be given the opportunity to link to a different Contact.
            </div>
            <div class="unlinkBodyRight">
                <apex:outputpanel id="callMethod">
                    <apex:commandbutton value="Yes, this is the wrong contact" action="{!performUnlinkContact}" rerender="" status="myDisplayStatus" />&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="return hideUnlinkPanel()" style="color:blue;cursor:pointer;text-decoration:underline">No</a>
                </apex:outputpanel>
                <apex:actionStatus id="myDisplayStatus"  startText="(performing Contact Unlink...)"  stopText=""/>
            </div>
        </div>
    </div>
</apex:component>
    <input type="button" value="Yes, this is the wrong contact" onclick="doUnlink();" />


到目前为止,此方法似乎工作得很好。

您还可以使用ApexPages.Action类型的apex:属性将performUnlinkContact()的引用传递给组件,然后当commandButton使用此引用时,它将调用页面控制器中定义的方法

<apex:component>
    <apex:attribute name="performUnlinkContact" type="ApexPages.Action" description="Passing method from controller"/>
    <!-- your stuff here -->
</apex:component>

然后,在使用组件时,必须按如下方式填充该属性:

<c:MyComponent performUnlinkContact="{!performUnlinkContact}"

只是想澄清一下……您有一个用于VF页面的控制器(但没有用于组件的单独控制器),并且您正试图从组件调用
performUnlinkContact
方法(存在于页面的控制器中)?是的,我正在使用一个名为LeadControllerExtension的控制器扩展。这就是方法
performUnlinkContact
存在的地方。emmancsu是正确的。我认为您需要将代码移动到组件控制器。尝试将PerformLink移动到组件使用的另一个控制器类。请参阅以供参考。