3

I have a commandButton in a visualforce component. The expected behavior is that the controller method would be called. The page is refreshed, but the method registered in the commandButton {!performUnlinkContact} is not called. The strange thing is that if I put the button on the base visualforce page, it calls the controller method as expected - but when in a component, it does not.

Here is my component:

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

and here is the method in the controller extension:

public PageReference performUnlinkContact() {
     System.debug('==================================!!performUnlink');
    if (this.thisLead.rkContactId__c != 0) {
        this.thisLead.rkContactId__c = 0;

        update this.thisLead;
    }

    return null;
}

I'm sure I must be doing something wrong since I am new to salesforce and still learning, but I am unable to find any related issues when I search on how to resolve this issue. Thanks in advance for the help.

3
  • Just to be clear...you have a controller for the VF page (but no separate controller for the component), and you're attempting to call the performUnlinkContact method (which exists in the page's controller) from the component? Commented Sep 19, 2012 at 19:36
  • Yes I am using a controller extension called LeadControllerExtension. This is where the method performUnlinkContact lives. Commented Sep 19, 2012 at 19:55
  • emmancsu is right. I think that you need to move the code to the component controller. Try moving the performUnlink to another controller class used by the component. See salesforce.com/us/developer/docs/pages/Content/… for reference. Commented Sep 20, 2012 at 3:14

3 Answers 3

2

Thanks for the replies - to resolve I ended up adding an actionFunction to the base Page, then just calling this function in the component via a button's onclick event:

Code in base page:

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

Code to call function in the component:

    <input type="button" value="Yes, this is the wrong contact" onclick="doUnlink();" />

This method seems to work well so far.

Sign up to request clarification or add additional context in comments.

Comments

2

You can also pass a reference of performUnlinkContact() to the component, using an apex:attribute of type ApexPages.Action, and then when your commandButton uses this reference, it will call the method defined in the page controller.

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

Then when you use your component, you have to populate that attribute like so:

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

Comments

0

I think rerender="" is not a way to do a fake reRender command. I would try it with rerender="none".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.