I’m trying to build a VF component that references an attribute that is an instance of an inner class. I followed the suggestion here on the Apex boards but it does not compile for me using V28.0. (Note the boards post was about lists of inner class objects – I only need a single instance)
Interface, Apex class, VF component follow:
public interface VFComponentAttributable { // To make inner classes available as VF component attributes // http://boards.developerforce.com/t5/Visualforce-Development/Error-using-inner-class-in-component-attribute/td-p/147856 } public with sharing class Foo { public class InnerBar implements VFComponentAttributable{ public String myVbl {get; set;} } } <apex:component > <!-- Generates compiler error 'Unknown property VFComponentAttributable.myVbl' --> <apex:attribute name="bar" description="instance of inner class" type="VFComponentAttributable" required="true"/> <apex:outputText value="{!bar.myVbl}"/> <!-- This doesnt work either, generates compiler error 'Apex class InnerBar does not exist <apex:attribute name="bar" description="instance of inner class" type="Foo.InnerBar" required="true"/> <apex:outputText value="{!bar.myVbl}"/> -->
I know I can refactor and make the inner class an outer class and it will work but I’d rather not if I can avoid it.
Answer
I’ve run across this as well and also resorted to refactoring my inner-class to the top level. The documentation isn’t clear on this, but considering that the type attribute is considered limited, I think it’s fair to assume that only top-level classes are supported. From the Visualforce Developer’s Guide (pg. 285):
Only the following data types are
allowed as values for the type attribute:
- Primitives, such as String, Integer, or Boolean.
- sObjects, such as Account, My_Custom_Object__c, or the generic sObject type.
- One-dimensional lists, specified using array-notation, such as String[], or Contact[].
- Maps, specified using type=”map”. You don’t need to specify the map’s specific data type.
- Custom Apex types (classes).
Attribution
Source : Link , Question Author : cropredy , Answer Author : Adam