You need to sign in to do that
Don't have an account?
Problems accessing public method in custom class passed to custom component
There must be something subtle I'm missing here. Component documentation states that attributes in custom components can be custom types, yet, the component (snippet) below simply refuses to acknowledge a public method in a custom type. The attribute in red below gives a null pointer exception. If I call the "getter" directly, it doesn't recognize the method name.
Ideas, folks? Oh, and the reason I need this is I'm testing out ways to write my own object layouts, since Apex doesn't have access to layout info (yet).
Thanks!
Grant
public class CaseLayout {
public List<ApexPages.Action> m_actions;
public List<ApexPages.Action> getM_actions() {
if (m_actions == null) {
m_actions = new List<ApexPages.Action>();
m_actions.add(new ApexPages.Action('{!Save}'));
m_actions.add(new ApexPages.Action('{!Case.Edit}'));
}
return m_actions;
}
public void setM_actions(List<ApexPages.Action> actions) {
m_actions = actions;
}
}
<apex:component>
<apex:attribute name="case" description="Incoming case object" type="Case"/>
<apex:attribute name="layout" description="Incoming Case Layout object" type="CaseLayout"/>
<apex:form >
<apex:pageBlock title="{!$ObjectType.case.label}">
<apex:pageBlockButtons >
<apex:repeat value="{!layout.m_actions}" var="v_action">
<apex:commandButton action="{!URLFOR(v_action)}" value="Edit"/>
</apex:repeat>
etc
etc
Unless I'm mistaken, an NPE here means that the value of "layout" is null when the VF page tries to invoke the method -- not so much that it can't see the method, but that it thinks there's no object on which to call it.
How is the layout object receiving its value in the VF page?
That's what I figured was happening, but since the layout is defined as an apex:attribute, I wouldn't expect it to need a value assigned directly in the component itself. It's assumed the caller of the component will assign a value to it
The one other thing I tried was telling the system the layout attribute is required, but no luck there either:
<apex:component>
<apex:attribute name="case" description="Incoming case object" type="Case"/>
<apex:attribute required="true" name="layout" description="Incoming Case Layout object" type="CaseLayout"/>
<apex:form >
<apex:pageBlock title="{!$ObjectType.case.label}">
<apex:pageBlockButtons >
<apex:repeat value="{!layout.m_actions}" var="v_action">
<apex:commandButton action="{!URLFOR(v_action)}" value="Edit"/>
</apex:repeat>
etc
etc
Update, not a bug. Apparently I had the wrong type. Apparently there is no type for SObject fields yet:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=4139