Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Browserfield.displayContent with <frame> that has an external url
    text
    copied!<p>I am trying to create a screen for a blackberry 5.0+ app that has a banner at the top and then a <code>Browserfield</code> underneath that views an external site. The banner is hosted on one site and the content for the <code>BrowserField</code> is hosted on another.</p> <p>Originally I tried using 2 BrowserFields but had issues when several devices did not display the banner and only showed the content underneath. Furthermore when another screen with the same setup was displayed the app would crash with an <code>IllegalStateException</code>. I did a bit of research and it seems that <code>BrowserField</code> seems to have some <a href="http://supportforums.blackberry.com/t5/Java-Development/Dealing-with-several-BrowserFields-Blank/td-p/1111787" rel="nofollow noreferrer">trouble when several instances of it exist at once.</a> </p> <p>So in order to get around this issue I have combined both <code>BrowserField</code>s into one, using the <a href="http://www.w3schools.com/tags/tag_frame.asp" rel="nofollow noreferrer">frame tag in html</a>, with the hopes of displaying the Banner ad in the first frame and the content underneath in the second frame.</p> <p>The html I made works in a normal browser:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;frameset rows="10%,90%"&gt; &lt;frame scrolling="no" src="http://4.bp.blogspot.com/_CZ1HhhanNgc/TI0xscVLW8I/AAAAAAAABps/sfeO4E3234k/s1600/head-mp-700x88.jpg" noresize="noresize" frameborder="0"&gt; &lt;frame src="http://www.penny-arcade.com" frameborder="0"&gt; &lt;/frameset&gt; &lt;/html&gt; </code></pre> <p>What I am doing is reading the html in as text, removing the <code>\n</code> and <code>\r</code>s and then putting it in the following method: <code>browserField.displayContent(html,"http://localhost");</code></p> <p><a href="http://docs.blackberry.com/en/developers/deliverables/11958/Display_HTML_in_a_browser_field_825639_11.jsp" rel="nofollow noreferrer">This method is supposed to display the html in the browser</a>, but instead on the simulator I get this:</p> <p><img src="https://i.stack.imgur.com/yv6Xd.png" alt="enter image description here"></p> <p>On the device I get a blank screen. I don't know whats going on with the <code>displayContent()</code> method, so I would assume that it doesn't allow external sites? I don't really know what my options are from this point on. Is there some kind of fix for this, some library that I can use or some other way to implement this? </p> <hr> <h1>Edit:</h1> <p>So @Nate suggested a change to the <code>DOCTYPE</code> tag, and posted a screenshot of the html working. However I did this and I still get the same results, so I am going to post the code I'm using to make the screen. Here it is:</p> <pre><code>public final class MyScreen extends MainScreen { /** * Creates a new MyScreen object */ private BrowserField browserField; public MyScreen() { // Set the displayed title of the screen setTitle("MyTitle"); BrowserFieldConfig config = new BrowserFieldConfig(); config.setProperty(BrowserFieldConfig.VIEWPORT_WIDTH, new Integer(Display.getWidth())); config.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER); config.setProperty(BrowserFieldConfig.INITIAL_SCALE, new Float(1.0)); config.setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.FALSE); //supposed to prevent InvalidStateException from refreshing sometimes ProtocolController eventsProtocolController = new ProtocolController(browserField) { public void handleNavigationRequest(BrowserFieldRequest request) throws Exception { browserField.setFocus(); super.handleNavigationRequest(request); } }; config.setProperty(BrowserFieldConfig.CONTROLLER, eventsProtocolController); browserField = new BrowserField(config); try { String embeddedLinkFrame = readTextFile("frame.html"); browserField.displayContent(embeddedLinkFrame, "http://localhost"); } catch (Exception e) { System.out.println(e.getMessage()); } add(browserField); } public String readTextFile(String fName) { String result = null; DataInputStream is = null; try { is = new DataInputStream(getClass().getResourceAsStream("/" + fName)); byte[] data = IOUtilities.streamToBytes(is); result = new String(data); } catch (IOException e) { System.out.println(e.getMessage()); } finally { try { if (null != is) is.close(); } catch (IOException e) { System.out.println(e.getMessage()); } } return result; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload