You need to sign in to do that
Don't have an account?
ravi kiran 87
Create multiple columns on VF page based on different queries.
I have a requirement where I have to display mutliple columns from different objects on a single VF page
i'm trying to display but the way its binding is improper.
public class YourController {
public String GetAttributes { get; set; }
public List<Vehicle> vehicles { get; set; }
public YourController() {
vehicles = new List<Vehicle>();
List<account> cars = [SELECT Id, Name, Description FROM account];
List<contact> planes = [SELECT Id, name , Title FROM contact];
for(account car : cars) {
system.debug('car value in the loop ---> '+car.name);
vehicles.add(new Vehicle(car));
}
for(contact plane : planes) {
system.debug('Plane value in the loop ---> '+plane.title);
vehicles.add(new Vehicle(plane));
}
}
public List<contact> GetAttributes(){
List<contact> attr = [SELECT Name from contact limit 10];
return attr;
}
public class Vehicle {
public Id id { get; set; }
public string name { get; set; }
public string name1{ get; set; }
public Vehicle(account car) {
// this.id = car.Id;
this.name = car.name;
// this.desc = car.desc;
}
public Vehicle(contact plane) {
// this.id = plane.Id;
this.name1 = plane.title;
//this.desc = plane.desc;
}
}
}
VF page code
<apex:page controller="YourController" >
<apex:form >
<apex:pageBlock ><apex:pageBlockTable value="{!vehicles}" var="vehicle">
<!--- <apex:column headerValue="Id" value="{!vehicle.id}" /> --->
<apex:column headerValue="FirstName" value="{!vehicle.name}" />
<apex:column headerValue="Name" value="{!vehicle.name1}" />
<apex:pageBlockSection title="Vitality Check Attributes">
<apex:pageBlock >
<apex:repeat value="{!Attributes}" var="att">
</apex:repeat>
</apex:pageBlock>
</apex:pageBlockSection>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
i'm trying to display but the way its binding is improper.
public class YourController {
public String GetAttributes { get; set; }
public List<Vehicle> vehicles { get; set; }
public YourController() {
vehicles = new List<Vehicle>();
List<account> cars = [SELECT Id, Name, Description FROM account];
List<contact> planes = [SELECT Id, name , Title FROM contact];
for(account car : cars) {
system.debug('car value in the loop ---> '+car.name);
vehicles.add(new Vehicle(car));
}
for(contact plane : planes) {
system.debug('Plane value in the loop ---> '+plane.title);
vehicles.add(new Vehicle(plane));
}
}
public List<contact> GetAttributes(){
List<contact> attr = [SELECT Name from contact limit 10];
return attr;
}
public class Vehicle {
public Id id { get; set; }
public string name { get; set; }
public string name1{ get; set; }
public Vehicle(account car) {
// this.id = car.Id;
this.name = car.name;
// this.desc = car.desc;
}
public Vehicle(contact plane) {
// this.id = plane.Id;
this.name1 = plane.title;
//this.desc = plane.desc;
}
}
}
VF page code
<apex:page controller="YourController" >
<apex:form >
<apex:pageBlock ><apex:pageBlockTable value="{!vehicles}" var="vehicle">
<!--- <apex:column headerValue="Id" value="{!vehicle.id}" /> --->
<apex:column headerValue="FirstName" value="{!vehicle.name}" />
<apex:column headerValue="Name" value="{!vehicle.name1}" />
<apex:pageBlockSection title="Vitality Check Attributes">
<apex:pageBlock >
<apex:repeat value="{!Attributes}" var="att">
</apex:repeat>
</apex:pageBlock>
</apex:pageBlockSection>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Here Below is the code