function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gliugliu 

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

 

slaneslane

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?

gliugliu

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

 

gliugliu
It doesn't look like an access problem, it seems something is special about the ApexPages.Action class. If I try to access a List of any other class within the layout attribute (for instance, a list of strings), it works fine. Looks like a bug to me.
gliugliu

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