6

I have an apex component which displays a list of Albums and Images under each album.

Here is the code for the component

global class AttachmentModel {
public ID Id;
public DateTime CreatedDate;
public String FileName;
public String Description;
public String ParentId;
public String ActualSizeExId;
public String FullSizeExId;
public String ThumbnailExId;
public String FullSizeUrl;
public String ThumbnailUrl;
public Decimal FileSize;
public String FileType; 
 }


<apex:component >
<apex:attribute name="albums" description="" type="Album__c[]" required="true" />
<apex:attribute name="images" description="" type="map" required="true" />
<apex:pageBlock>    
    <div class="content-section">
        <apex:repeat value="{!albums}" var="album">            
            <apex:repeat value="{!images[album.id]}" var="image">    
                    <div class="photo-item-container">
                        <apex:outputField value="{!album.name}"/>                               
                        <apex:image value="{!image.ThumbnailUrl}" width="200" height="200" />
                        <apex:outputText value="{!image.FileName}"/>
                        <apex:outputText value="{!image.Description}"/>
                    </div>
               </apex:repeat>            
        </apex:repeat>
    </div>
</apex:pageBlock> 
</apex:component>
  • Attribute 'albums' is pass in as List === a list of Sobject 'Album__c'
  • Attribute 'images' is pass in as Map> === a map of 'Album' Id and its Attachment(Image) list. Note that AttachmentModel is a custom model class I created in apex. the Code is posted above.

The problem is that Every time when this component is invoke, system throw error: Unknown Property: ournamespace.AttachmentModel.ThumbnailUrl

It seems like the system can recognize the datamodel type but fail to recognize the properties under it.

Need your help to figure out why.

Thank you!

0

1 Answer 1

8

I'm fairly certain that you need a getter on each of the properties of your sub-class.

global class AttachmentModel {
     public ID Id { get; private set; }
     public DateTime CreatedDate { get; private set; }
     public String FileName { get; private set; }
     public String Description { get; private set; }
     public String ParentId { get; private set; }
     public String ActualSizeExId { get; private set; }
     public String FullSizeExId { get; private set; }
     public String ThumbnailExId { get; private set; }
     public String FullSizeUrl { get; private set; }
     public String ThumbnailUrl { get; private set; }
     public Decimal FileSize { get; private set; }
     public String FileType { get; private set; }
}
2
  • greenstork, why we need getter setter for the sub-class? Also, why it has been set as private for set? Please help me to understand.
    – Bforce
    Commented Apr 17, 2014 at 12:39
  • The private set means that you are only able to set the variable from within your code. Public is needed to accept a user input from a Visualforce page.
    – greenstork
    Commented Apr 17, 2014 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .