I have a VF Page that uses a standard Account controller and a controller extension to show information from a related object (Contact) - similar in function to a related list.
I need to have multiple versions of this page for different related objects, for example Opportunity and a custom object. The various pages will be embedded in a standard page layout, so each must be a separate page (not a VF Component).
The VF page and the controller extension logic make heavy use of Fieldsets, so the difference between the various VF pages will be minimal: each will reference a different title, a different fieldset, and each may contain different command buttons. I would extract most of the common code into a custom component, however, I can't find a way to pass an arbitrary set of command buttons into a custom component. Instead, I will probably use apex:composition to allow the various VF pages to share a common template.
The problem is the controller extension - the logic is very generic, but I need to pass the related object type (e.g., Contact, Opportunity) into the controller extension. Here are solutions I've considered and the issues with each:
Pass the object type as an URL param- This is a security risk; I want the object type to be hardcoded per page.
Use a hidden input field to pass the object type name- This is a security risk; I want the object type to be encoded only in the VF markup and not to be settable from the client.
Pass a value using
apex:param. While I can add an
apex:paramto a VF page, values passed this way are ignored, even if using
assignToto reference a declared property. To correctly use an apex:param, I would need to move my code into an
apex:attributeto match the param to a controller property. But as outlined above, I can't use a component, because I need to include an arbitrary set of command buttons in my page markup. If I could mix
apex:componentI'd be fine, but templates must be VF Pages.
Use an existing attribute of the VF page.
tabStylewould be perfect, since it is meant to refer to a standard or custom object type. However, I can find no way for the controller code to determine the
tabStyledeclared on the
Render the whole page as Dynamic VF from my controller code. This is a non-starter for many reasons I won't cover here.
So I'm stuck. I need to pass a parameter to my controller extension, but it cannot be accessible from the client, leaving only the VF page markup. I cannot find any way to pass data from markup into the controller. Due to the nature of the templating I need to do (command buttons), I can find no workable way to move my markup into a custom VF component to enable the use of
apex:param. Have I overlooked any options?
Note: While typing this up, I can up with one more (bad) idea:
- Use a VF Page naming convention in combination with
ApexPages.CurrentPage().getURL()to allow the controller to infer the related object name from the VF Page. Feels like bad design, but may get the job done. Will experiment but clearly not optimal solution.