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
KRayKRay 

Accessing Webservice Data from Visualforce page

Good Evening Guys/Ladies, I've been banging my head with issue all day. I want to view specific fields from the Web Service, I can view the "bulk" data but I can't view let's say ONLY the make OR model fields using dot notation. I've posted a minimized/simplified verision of my code. Please help thanks 

Here's what it returns:
Cars:[Make=Lamborghini, Make_type_info=(Make, http://microsoft.com/webservices/, null, 0, 1, false), Model=Gallardo,Model_type_info=(Model, http://microsoft.com/webservices/, null, 0, 1, false)] Cars:[Make=Lamborghini, Make_type_info=(Make, http://microsoft.com/webservices/, null, 0, 1, false), Model=Aventador,Model_type_info=(Model, http://microsoft.com/webservices/, null, 0, 1, false)]

I want to return lets say, the "model" field only using {!Sale.model} on the visualforce page.

<!--WebService -->
<!-- Minimized version -->

public Class ExternalCarLot{

public  Car{
        public String Make;
        public String Model;
}

public ArrayOfCars{
      public ExternalCarLot.Car[] Cars;
}
public class SalesForceMobileSoap{
      WebServiceCallout.invoke();
}
ExternalCarLot.ArrayOfCars FindCarByMake(String make){
     WebServiceCallout.invoke();
}
}

<!-- Controller -->
public class CallWBSvc{

public List<ExternalCarLot.Car> getCars(){
   ExternalCarLot.SalesForceMobileSoap callWebService = ExternalCarLot.SalesForceMobileSoap();

   ExternalCarLot.ArrayOfCars CarStorage = new ExternalCarLot.ArrayOfCars();

   List<ExternalCarLot.Car> passBack = new List<ExternalCarLot.Car>();

   CarStorage = callWebService.FindCarByMake('Lamborghini');

for(ExternalCarLot.Car tom : CarStorage.Cars){
   passBack.add(tom);
   }
return passBack;
}

<!-- VF Page -->
<apex:page controller="CallWBSvc">

     <apex:repeat value="{!Cars}" var="Sale">
         <apex:outputText value="{!Sale}" /> 
     </apex:repeat>
</apex:page>

Best Answer chosen by KRay
KRayKRay
I figured it out. I've tried this solution like (2) times before but it didn't work.  It works now and that's all that matters. #Weird


<!--Solution -->
I created a CarList class within the controller and used the CarList constructor to create a CarList for each car returned from the webservice. Then I passed that list back to the VFPage, see below. Using the code below, I'm now able to access each individual field using dot notation, {!Sale.Make} or {!Sale.Model}. #Weird


public class CarList{
public String Model{get; set;}
public String Make{get; set;}

public CarList(String Mo, String Mk){
this.Model = Mo;
this.Make = Ma;
}
}

public List<CarList> getCars(){
   ExternalCarLot.SalesForceMobileSoap callWebService = ExternalCarLot.SalesForceMobileSoap();

   ExternalCarLot.ArrayOfCars CarStorage = new ExternalCarLot.ArrayOfCars();

   List<CarList> passBack = new List<CarList>();

   CarStorage = callWebService.FindCarByMake('Lamborghini');

for(ExternalCarLot.Car tom : CarStorage.Cars){
   passBack.add(tom.Model, tom.Make);
   }
return passBack;
}

All Answers

Avidev9Avidev9
By the output looks like Sale.Model will work.
It should be something like

<apex:page controller="CallWBSvc">

     <apex:repeat value="{!Cars}" var="Sale">
         <apex:outputText value="{!Sale.Model}" /> 
     </apex:repeat>
</apex:page>


KRayKRay
@Avidev9, When I use {!Sale.Model}. I receive an "Unknown Property 'ExternalCarLot.Car.Model'"  error message.
KRayKRay
I figured it out. I've tried this solution like (2) times before but it didn't work.  It works now and that's all that matters. #Weird


<!--Solution -->
I created a CarList class within the controller and used the CarList constructor to create a CarList for each car returned from the webservice. Then I passed that list back to the VFPage, see below. Using the code below, I'm now able to access each individual field using dot notation, {!Sale.Make} or {!Sale.Model}. #Weird


public class CarList{
public String Model{get; set;}
public String Make{get; set;}

public CarList(String Mo, String Mk){
this.Model = Mo;
this.Make = Ma;
}
}

public List<CarList> getCars(){
   ExternalCarLot.SalesForceMobileSoap callWebService = ExternalCarLot.SalesForceMobileSoap();

   ExternalCarLot.ArrayOfCars CarStorage = new ExternalCarLot.ArrayOfCars();

   List<CarList> passBack = new List<CarList>();

   CarStorage = callWebService.FindCarByMake('Lamborghini');

for(ExternalCarLot.Car tom : CarStorage.Cars){
   passBack.add(tom.Model, tom.Make);
   }
return passBack;
}

This was selected as the best answer