Monday, December 12, 2016

Visualforce - Beyond Basics Series 17 - Pass actions to component

What types you can pass to component ?

Custom components can take these types,

  • Primitive Types
  • sObjects
  • Collections (Set, List, Map)
  • Classes in System Namespace
    •   SelectOption
    •   ApexPages.Action, etc
  • Custom Class/Interface

How to make component more generic ?

A component can take any form of data that could be either System defined type or custom type. So, that will cover most of the use case for components. But, as a bonus, you could pass ApexPages.Action type, which will be invoked during specific event inside the component.


How to do it ?

you need to add a attribute tag which will take the ApexPages.Action type & store it in a variable. Then, when some event happens in the component, it invokes the action.


Where is code ?

I have illustrated the simple action passed to a controller which will call this when user changes the value in the text field.



No comments:

Post a Comment

Thanks for reading my blog !