This question is similar to How to call a standard controller action of a VF page from a VF component, but there are two differences I see:
- I'm not using a standard controller
- the
<apex:form>
tags are in my component
I am trying to get the commandButton on the component to call the addMethod
method on my extension. For whatever reason, this isn't happening. Nothing shows in the debug logs, so it doesn't appear to be working. There are no errors or exceptions thrown.
Should this be possible?
Update: The page uses an apex:repeat
element, there's an onClick on the commandButton, the rendered value looks at the record type
My page
<apex:page standardController="Custom_Object__c" extensions="CustomObjectExtension">
... some content
<apex:repeat value="{!childObjects}" var="cObject">
<c:componentWithForm addMethodAction="{!addMethod}" rendered="{!cObject.RecordType.Name == 'My Record Type'} />
</apex:repeat>
... more content
</apex:page>
Where the childObjects
in the repeat element is a List
My component
<apex:component>
<apex:attribute name="addMethodAction" type="ApexPages.Action" ... />
<apex:form>
<apex:inputText ... />
<apex:commandButton onclick="return someFunction();" action="{!addMethodAction}" />
</apex:form>
</apex:component>
My extension
public class CustomObjectExtension
{
public List<Child_Object__c> childObjects {get; set;}
public CustomObjectExtension(ApexPages.StandardController stdController)
{
.. do stuff
childObjects = [SELECT ... FROM Child_Object__c];
}
public PageReference addMethod()
{
.. do stuff
}
}