0

I want to show the results of a Json response on a Visualforce page. At this moment im able to deserialize and show the results, but when I try to show the result of the Class in the visual force it shows the following error:

enter image description here

For testing i want to show in the VF page "Razon Social" of the class Empresa.

This is the class:

public class EquifaxEmpresa {

public List<Empresa> Empresa;

public class Empresa{
    public String RazonSocial; 
    public String NombreComercial;  
    public String TipoContribuyente; 
    public String EstadoContribuyente;
    public String CondicionContribuyente; 
    public String Dependencia; 
    public String CodigoCIIU; 
    public String DescripcionCIIU; 
    public String InicioActividades; 
    public String ActividadComercioExterior; 
    public String NumeroTrabajadores; 
    public String Direccion;
}
public static EquifaxEmpresa parse(String json){
    return (EquifaxEmpresa) System.JSON.deserialize(json, EquifaxEmpresa.class);
}}

This is the controller class:

global class equifaxController {
public String idConsulta {get;set;}
public EquifaxEmpresa theEmpresa {get;set;}
public String mensaje {get;set;}

public void consultaPersona(){

    string msj = '{'+
                 '"NroDocumento":"'+idConsulta+'",'+
                 '"Consulta":"Empresa"'+
                 '}';

    Http http = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('endpoint here');
    req.setBody(msj);
    req.setMethod('POST');
    req.setHeader('Content-Type','application/json');
    req.setTimeout(12000);

    HttpResponse res = new HttpResponse();

    //EquifaxEmpresa empresita = (EquifaxEmpresa)JSON.deserialize(msj, EquifaxEmpresa.class);

    res = Http.send(req);
    String temp = res.toString();

    if(temp.contains('Error')){
        system.debug('Error: '+res.getStatusCode());
    }else{
        String body = res.getBody();
        theEmpresa = EquifaxEmpresa.parse(body);
        system.debug(theEmpresa.Empresa[0].RazonSocial);
        mensaje = body;
    }
}
}

The visualforce page:

<apex:page controller="equifaxController">


       <apex:pageBlock title="Datos de Empresa">
           <apex:form >
            <apex:inputText value="{!idConsulta }"/>
            <apex:commandButton value="Consultar" action="{!consultaPersona}" reRender="dynamic"/>
           </apex:form>
       </apex:pageBlock>


    <apex:outputPanel id="dynamic">
        {!theEmpresa.Empresa[0].RazonSocial}
    </apex:outputPanel>   

</apex:page>

The other thing that I cannot understand, its why system.debug shows me {!theEmpresa.Empresa[0].RazonSocial} and VF not:

enter image description here

Thanks in advance

1
  • 1
    I think declaring it like this public List<Empresa> Empresa {get;set} should solve the issue. Jan 3 '20 at 16:31
1

Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions.

So declare the list like this:

public List<Empresa> Empresa {get;set}
public String RazonSocial {get;set}
5
  • In the problems section appears: Invalid Type: Empresa Jan 3 '20 at 16:48
  • 1
    Refer the updated answer. Jan 3 '20 at 16:50
  • these declarations go in the Controller or the empresa class? Thanks for your help. Jan 3 '20 at 16:53
  • 2
    Yes, you've already declared it, just append it with getter and setters Jan 3 '20 at 16:54
  • 1
    Thanks!! It worked. Jan 3 '20 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.