05-14-2010 10:55 AM
I'm trying to supply my own content to a BrowserField2. By my own content, I mean, I supply the html from my program. So, say a request was made for page aaaa.html, then I could supply "<html><body>This is page aaa</body></html>.
I'm using an approach that, according to my reading of the API, should allow this. However it is not working.
The approach I'm using involves establishing my own protocol, and then processing this.
BrowserField2 allows you to specify the ProtocolController and this Object allows you specify handlers that will assist with navigation and supply resources. You can associate a protocol with these handlers.
So I have created my own ProtocolController, created an object that handles both navigation and resource requests and told the ProtocolController to use my handler. I then told the BrowserFieldConfiguration to use my ProtocolController. And then I try to display a page, using my protocol.
It all looks like it works. But the request to get the page never happens. The request to navigate to it does. I see the output from this line:
System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + request.getURL());
but I never see anything form this:
System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + resourceURI);
The BrowserField displays but is blank.
Anyone any idea what I'm doing wrong?
Code that I'm using is pasted below.
class MyBrowserField2Sample extends UiApplication {
private MainScreen _screen;
private BrowserField _bf2;
private ProtocolController _myProtocolController;
private BrowserFieldConfig _myBrowserFieldConfig;
private BrowserFieldRequestHandler _browserRequestHandler;
MyBrowserField2Sample() {
_browserRequestHandler = new BrowserFieldRequestHandler();
_myBrowserFieldConfig = new BrowserFieldConfig();
_bf2 = new BrowserField(_myBrowserFieldConfig);
_myProtocolController = new ProtocolController(_bf2);
_myBrowserFieldConfig.setProperty(BrowserFieldConf ig.CONTROLLER, _myProtocolController);
String myProtocol = "test";
_myProtocolController.setNavigationRequestHandler( myProtocol, _browserRequestHandler);
_myProtocolController.setResourceRequestHandler(my Protocol, _browserRequestHandler);
_screen = new MainScreen();
_screen.add(_bf2);
pushScreen(_screen);
String addressToDisplay = "test://www.rim.com/index.html";
_bf2.requestContent(addressToDisplay);
}
public static void main(String[] args) {
MyBrowserField2Sample app = new MyBrowserField2Sample();
app.enterEventDispatcher();
}
}
public class BrowserFieldRequestHandler extends Object
implements BrowserFieldResourceRequestHandler, BrowserFieldNavigationRequestHandler {
public void handleNavigation(BrowserFieldRequest request) throws Exception {
System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + request.getURL());
}
public InputConnection handleResource(BrowserFieldRequest request) throws Exception {
String resourceURI = request.getURL();
System.out.println("BrowserFieldRequesthandler - handleNavigationRequest: " + resourceURI);
String contentMessage = "Requested content: " + resourceURI;
String webData = "<html><body>" + contentMessage + "</body></html>";
return new BrowserFieldResponse(resourceURI, webData.getBytes(), HttpProtocolConstants.CONTENT_TYPE_TEXT_HTML);
}
}
07-18-2010 04:11 AM
Hi,
If you want to just supply the static content to bf2 then there is an easy option available by invoking the
api bf2.requestContent("local:///mysample.html")
hope this helps.