You need to sign in to do that
Don't have an account?
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!
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:
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.