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
Nick Van DusenNick Van Dusen 

Custom list controller - how do I return properties?

I'm coding a custom list controller to retrieve a list of images from a third-party site. I'd like to show filename, size, and eventually buttons for interacting with the images via RESTful HTTP calls. I'm new to Apex, and am stumbling around trying to figure out how to create properties so I can list them on a Visualforce page.

 

Here's my Visualforce code:

<apex:page standardController="Inventory_Unit__c" extensions="InventoryImageListExtension">
<apex:pageBlock>
    <apex:pageBlockTable value="{!listImages}" var="img"> 
        <apex:column value="{!img.fileName}"/> 
    </apex:pageBlockTable>    
</apex:pageBlock>
</apex:page>

 

And my Apex class (such as it is)

public class InventoryImageListExtension {
    private Final Inventory_Unit__c controller;
    public InventoryImageListExtension(ApexPages.StandardController c) { 
        this.controller = (Inventory_Unit__c)c.getRecord();
    }
    
    public Map<String,String> getListImages() {
        Map<String,String> imageMap = new Map<String,String>();
        imageMap.put('fileName','test.jpg');
        return imageMap;
    }
}

 

I'm sure I should be using Lists or maybe a Map with another Map inside it, but I'm just completely confused on how to get something like {!img.propertyName} to work. Can anyone help? Thanks!

Nick Van DusenNick Van Dusen

I managed to figure it out while looking for an answer on an unrelated project. I didn't realize you could create a class inside another class to define new types:

    public class ImageObject {
        public String fileName {get; set;}
        public Integer fileSize {get; set;}
    }

    public List<ImageObject> getListImages() {
        List<ImageObject> imageList = new List<ImageObject>();
        
        // loop wrapper start
        ImageObject imgObj = new ImageObject();
        imgObj.fileName = 'test.jpg';
        imgObj.fileSize = 20492;
        imageList.add(imgObj);
        // end loop
        
        return imageList;
    }

 

Pradeep_NavatarPradeep_Navatar

You can use wrapper class to include more values :

 

            public List<WrapperQueAns> lstimg = new List<WrapperQueAns>{};

            public List<WrapperQueAns> listImages { get { return lstimg; } set { lstimg = value; } }

                                                Public InventoryImageListExtension()

                                                {

                                                   Populateimage();

                                                }

                                                public void Populateimage()

                                                {

                                                    WrapperQueAns wqa = new WrapperQueAns();

                                                                wqa.Filename= 'test.jpg'';

                                                                lstimg.add(wqa);

 

                                                }

                                                public class WrapperQueAns

                                                {

                                                                public String Filename{ get; set; }

                                                                // any other property you can include here.

 

                                                }//End Class WrapperQueAns

 

Hope this helps.