0

Here is my controller

public with sharing class Search 
{ 
    public String strTag {get;set;}
    public String strlocation {get;set;}
    public String result {get;set;}
    public ResultSet data {get;set;}

    public PageReference find() {         

    HttpRequest req = new HttpRequest();
    HttpResponse res = new HttpResponse();
    Http http = new Http();

    req.setEndpoint('http://test.3spire.net/index.php?ins='+strTag+'&loc='+strlocation);
    req.setMethod('GET');

    //these parts of the POST you may want to customize
    req.setCompressed(false);
    req.setBody('key1=value1&key2=value2');
    req.setHeader('Content-Type', 'application/x-www-form-urlencoded');  

    try {
        res = http.send(req);       
    } catch(System.CalloutException e) {
        system.debug('Callout error: '+ e);
        result = ''+e;
    }

    data= JSON.deserialize(res.getBody(),ResultSet.class);

//    result = res.getBody();    
        return null;
    }

    public class ResultSet{       
        public Map<String, Result> resultSet;
    }

    public class Result
    {
        public String ins;
        public String loc;
    }
}

And this is my visulforce page

 <apex:pageBlock >
    <apex:pageBlockTable value="" var="var" id="table">
     <apex:column value="" />
     <apex:column value="" />
    </apex:pageBlockTable>
 </apex:pageBlock>

Now how can i bind the data with the interface

Thanks in advance

  • Dear @VamsiKrishna i saw that post but i don't get the idea how i use that on my case – moin khan Jan 5 '16 at 12:07
1

Use like below Few changes use get set Class

public with sharing class Search 
{ 
    public String strTag {get;set;}
    public String strlocation {get;set;}
    public String result {get;set;}
    public Map<String, Result> data {get;set;}

    public PageReference find() {         

    HttpRequest req = new HttpRequest();
    HttpResponse res = new HttpResponse();
    Http http = new Http();

    req.setEndpoint('http://test.3spire.net/index.php?ins='+strTag+'&loc='+strlocation);
    req.setMethod('GET');

    //these parts of the POST you may want to customize
    req.setCompressed(false);
    req.setBody('key1=value1&key2=value2');
    req.setHeader('Content-Type', 'application/x-www-form-urlencoded');  

    try {
        res = http.send(req);       
    } catch(System.CalloutException e) {
        system.debug('Callout error: '+ e);
        result = ''+e;
    }
    data= (Map<String, Result>)JSON.deserialize(res.getBody(),Map<String, Result>.class);

    result = res.getBody();    
        return null;
    }
    public class Result
    {
        public String ins {get;set;}
        public String loc {get;set;}
    }
}

VF page

<apex:page controller="Search">
    <apex:form>
            <apex:pageBlock > 
                <apex:pageBlockSection > 
                    <label>Industry</label> 
                    <apex:inputText value="{!strTag}"/> 
                    <label>Location</label> 
                    <apex:inputText value="{!strlocation}"/> 
                </apex:pageBlockSection> 
                <apex:pageBlockButtons > 
                    <apex:commandButton value="Search" action="{!find}" reRender="tableId,tableId2"/> 
                </apex:pageBlockButtons> 
            </apex:pageBlock>

        <apex:PageBlock id="tableId2"> 
            <apex:outputText value="{!result}"></apex:outputText> 
        </apex:PageBlock> 
        <apex:pageBlock id="tableId"> 
            <apex:pageBlockTable value="{!data}" var="var" id="table"> 
                <apex:column headerValue="Location"> 
                    <apex:outputText value="{!data[var].ins}"/> 
                </apex:column> 
                <apex:column headerValue="Insudtry"> 
                    <apex:outputText value="{!data[var].loc}"/> 
                </apex:column> 
            </apex:pageBlockTable> 
        </apex:pageBlock> 
</apex:form>
</apex:page> 
  • 1
    Adding an explanation of why this works would make the answer more valuable. – Keith C Jan 5 '16 at 12:11
  • Dear @Ratan this is not working – moin khan Jan 5 '16 at 12:12
  • @moinkhan I have updated ans check – Ratan Paul Jan 5 '16 at 12:20
  • Dean @Ratan im not sure is it working or not.but my questing is that is this data= JSON.deserialize(res.getBody(),ResultSet.class); returning something.How can i check that – moin khan Jan 5 '16 at 12:26
  • @moinkhan Yes it should work I have tested. check result in debug log. is there any problem on that – Ratan Paul Jan 5 '16 at 12:29
0

Assuming data to be the wrapper list

<apex:page controller="TestClass1">
<apex:form>
    <apex:pageBlock >
        <apex:pageBlockTable value="{!data.resultSet1.values}" var="var" id="table">
            <apex:column  > {var[0]}</apex:column>
            <apex:column  > {var[1]}</apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>

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