You need to sign in to do that
Don't have an account?

Unknown property error when trying to use custom class in data table
I'm trying to create a data table that has values from two different, unrelated objects. I couldn't find out a way to map the two objects together, so I created a custom class inside of my custom controller called ConvertItem. This is what the class looks like.
public class ConvertItem {
Boolean Convert;
String ProductName;
Double Quantity;
}
I have another method in the controller called getLineItems() that returns a List<ConvertItem>
public List<ConvertItem> getLineItems(){
// Grab the lineitems
List<OpportunityLineItem> LineItems = [Select Id, PricebookEntry.Name, Quantity, Description From OpportunityLineItem
where OpportunityId = :ApexPages.currentPage().getParameters().get('Id')];
// Create a list of ConvertItems to store the line item and asset info
List<ConvertItem> Items = new List<ConvertItem>();
// Put the line items in a generic sobject with asset information
for(OpportunityLineItem lineItem : LineItems){
ConvertItem newItem = new ConvertItem();
newItem.Convert=True;
newItem.ProductName=lineItem.PricebookEntry.Name;
newItem.Quantity=lineItem.Quantity;
newItem.AssetName=lineItem.PricebookEntry.Name;
Items.add(newItem);
}
System.Debug(Items);
return Items;
}
I have verified that it is returning a list in the debug logs, and that the list includes a ProductName for each item.
However, when I try to save the visualforce page that shows this list in a data table I get an error that ConvertItem.ProductName is an unknown property.
Here's the section of the visualforce page:
<apex:pageBlockTable value="{!LineItems}" var="item">
<apex:column value="{!item.ProductName}" />
</apex:pageBlockTable>
Anyone know why the visualforce page can't recognize that the ProductName is there?
Hello
In order to access the Properties(Variables) in your wrapper class you must have getter and setter methods for those variable. But in this case it is enough to have getter methods because you want only to display your data in VF page.
public class ConvertItem {
Boolean Convert;
String ProductName;
Double Quantity;
String AssetName;
public Boolean getConvert() { //getter method for Convert
return this.Convert;
}
public String getProductName() {//getter method for productName
return this.productName;
}
}
All Answers
Hello
In order to access the Properties(Variables) in your wrapper class you must have getter and setter methods for those variable. But in this case it is enough to have getter methods because you want only to display your data in VF page.
public class ConvertItem {
Boolean Convert;
String ProductName;
Double Quantity;
String AssetName;
public Boolean getConvert() { //getter method for Convert
return this.Convert;
}
public String getProductName() {//getter method for productName
return this.productName;
}
}
Thanks prageeth, that worked.
Why can you use a variable in a visualforce page by just saying {get; set;} but once it's in a wrapper class I have to use specific getter methods for each variable?
I tried writing String ProductName {get; set;} before I posted this question but that didn't work.
Hello Paul;
Your getter method is not visible in the VF page.
Use
public String ProductName {get; set;}
Instead of
String ProductName {get; set;}
Properties inside wrapper classes are accessible from VisualForce. Here's a wiki page with sample code, which helped me to implement something similar.
I have a similar problem, only I've done everything I can to make the variables in the wrapper class public. Nonetheless, it still isn't accessible from my Visualforce page.
Confusingly, I have another wrapper class in the controller that is set-up in the same way (as far as I can tell) and is fully accessible and working.
Has anybody any thoughts?
With thanks,
Andy
Hi Big Ears,
Accessing properties from VF pages does work, and there's a link above to working sample code. If your code does not work, could you post it here? I think you'll be more likely to get some help.
Shikibu,
Thanks for the post. I ended up working it out late last night. It wasn't a problem with accessibility in the end. I'd been an idiot and declared the variable "Quarter" (which I was using as the "var" attribute in the pageblocktable) somewhere else in my controller code. All fixed now.
With thanks,
Andy