I am trying to display the contents of a remote text file on a Visualforce Page. I have implemented a class called MyApexClass containing a getTextFileContentAsString method that returns the content of a remote text file as a string.
I then try to invoke that method in the Visualforce page and display it with apex:outputText like so "{!MyApexClass.TextFileContentAsString}". However, I get an error saying:
Error: Unknown property MyApexClass.TextFileContentAsString referenced in MyTemplate.
What is the correct way to invoke the method, and get the returned string to render on the VisualForce page?
Here are the Apex Class and the VisualForce page excerpts:
Apex Class:
public class MyApexClass {
public String getTextFileContentAsString() {
String url = 'http://somehost.com/theTextFile.txt';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
HttpResponse res = h.send(req);
return res.getBody();
}
}
VisualForce Page excerpt:
...
<div>
<apex:outputText value="{0}">
<apex:param value="{!MyApexClass.TextFileContentAsString}" />
</apex:outputText>
</div>
...
Do I need to do anything special to make the MyApexClass "visible" to the VisualForce page?