Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
anshulmittal_nsit
Posts: 15
Registered: ‎06-11-2010
My Device: NA

html rendering in blackberry

I want to render an html page.My aim is that i would pass a string containg a html and this should be displayed on the screen.

I have tried to use the following code

BrowserField browserField = new BrowserField();
String html = "<HTML><Body>HI</BODY></HTML>";
browserField.displayContent(html, url);

 in the url i first passed a null and it gave an exception.next i passed an arbitary url (of say google.com) but it showed a blank page.

 

I want to know how can a page be displayed with the html stored in a string.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: html rendering in blackberry

please use the search function, the question has been answered several times.

basically you have to encode the string correctly.

you can also look at the browserfield2demo for the browserfield2.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
dev2011
Posts: 17
Registered: ‎08-14-2009
My Device: Not Specified

Re: html rendering in blackberry

[ Edited ]

Keep in mind browserfield2 is only available on firmware 5.0+.

 

If you want to support lower devices and your HTML is really simple (just consisting of <b> and <i>) you'll probably are better of using this: http://supportforums.blackberry.com/t5/Java-Development/Simple-HTMLTextField-implementation/m-p/4543...

 

Otherwise it gets a little ugly as you'd have to implement you're own custom HttpConnection that takes it's data from a String instead of the web.

Contributor
anshulmittal_nsit
Posts: 15
Registered: ‎06-11-2010
My Device: NA

Re: html rendering in blackberry

browserContent = _renderingSession.getBrowserContent(connection, this, e);
if (browserContent != null) {
       Field field = browserContent.getDisplayableContent();
}

i think that i could use the above code but for this i need to extend httpconnection to write my own class to fetch data from a string rather than from internet.

I am a bit in trouble with extending this class.According to my understanding the connector class should also be extended and its open method should be override.Correct me if i am wrong

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: html rendering in blackberry

i think the code for it is somewhere on the forums, i would suggest to try different search parameters.

i don't have it in my own knowledge base unfortunately.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
anshulmittal_nsit
Posts: 15
Registered: ‎06-11-2010
My Device: NA

Re: html rendering in blackberry

 String HTML_STRING ="<b><i>ole ole </b></i>";
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        Base64OutputStream boutput = new Base64OutputStream( output );
        try {
			output.write( "data:text/html;base64,".getBytes() );
			boutput.write( HTML_STRING.getBytes() ); // HTML_STRING is the string containing your HTML content
			boutput.flush();
			boutput.close();
			output.flush();
			output.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
//        PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread("http://www.google.com", null, null, null, this);
		PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(output.toString(), null, null, null, this);
		thread.start();    

 

I have used the above code and it is rendering html alright.The html string is HTML_STRING .

Now i want that i can give path of an image in img src tag.Where should i save the image and which path should i give.

I tried saving it in the res folder and also the media card but it didnt work.Perhaps i didnt give the path correctly.Can anyone please provide me an example for this

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: html rendering in blackberry

[ Edited ]

You might find this Post/Thread has the answer, and saves you converting your input file too!

 

http://supportforums.blackberry.com/t5/Java-Development/Loading-a-local-html-file-in-the-browser/m-p....

 

Apologies, I just realised you were rendering this yourself and not invoking the Browser.  Sorry I don't actually know the anser to that question.  Perhaps the cod:// will work for your image.  Give it a try. 

Contributor
anshulmittal_nsit
Posts: 15
Registered: ‎06-11-2010
My Device: NA

Re: html rendering in blackberry

I have followed the following link and implemented httpconnection to create a class of my own 

'HttpConnectionImpl'

http://supportforums.blackberry.com/t5/Java-Development/Display-HTML-in-a-Screen-Field/m-p/335074/hi...

 and passed this to renderingSession.getBrowserContent.This sloves the issue of displaying a raw html.I pass the raw html input string to 'HttpConnectionImpl' constructor 

Now what i want is that i should be able to refresh the data(that is new data can be appended to the existing data or somechanges can be made to the data) and it should not require again invoking new HttpConnectionImpl(data) and again passing the connection thus obtained to renderingSession.getBrowserContent.Instead it should somehow itself resfresh the html rendering.

I belive that it would use javascript but i dont know how.Please suggest any solution or pointers