Reference inner class in Visualforce component
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).
The problem here is that your Component is receiving an instance of VFComponentAttributable
which does not have the myVbl
field.
If you change your VFComponentAttributable
and Foo
definitions to the following it should work.
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
String getMyVbl();
void setMyVbl(String value);
}
public with sharing class Foo
{
public class InnerBar implements VFComponentAttributable
{
private String myVbl;
public String getMyVbl()
{
return myVbl;
}
public void setMyVbl(String value)
{
myVbl = value;
}
}
}