You need to sign in to do that
Don't have an account?
Dynamic action value in component for buttons and links
I am trying to develop a reusable component that contains some stylized buttons. I want to include this component on all of the pages for a force.com app. The problem I am running into is that I want to pass the action for the commandlink/commandbutton tag into the component as an attribute and its not working. When I click a button that was included via the component with an action that was passed in, it just refreshes the page (via a post which, in the end, is what I want) and doesn't call my action. I am pretty sure its refreshing because the action method I am passing isn't being interpreted correctly in the component but I am not sure.
I am wondering if I need to change the type of the attribute in the component but not sure what to change it to...
Here is some code to help explain (lots of things ommitted to keep it simple).
Page:
<div>Some html
<c:myComponent myAction="myCustomAction"/>
Component
<apex:component>
<apex:attribute name="myAction" required="true" type="String" description=""/><apex:commandButton action="{!myAction}">My Button</apex:commandButton>
</apex:component>
Thanks for any help anyone can provide!
Bob, Thanks for your quick and most helpful reply! Your solution worked with one change.
We are now using the component in our pages as follows:
<c:myComponent myAction="{!ApexPages.Action.myCustomAction}"/>
Thanks again!
All Answers
You need to change the attribute type to ApexPages.Action, and change your component reference in the page to:
<c:myComponent myAction="{!myCustomAction}"/>
Bob, Thanks for your quick and most helpful reply! Your solution worked with one change.
We are now using the component in our pages as follows:
<c:myComponent myAction="{!ApexPages.Action.myCustomAction}"/>
Thanks again!