Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » two questions about custom widget?
two questions about custom widget? [message #1237240] Wed, 29 January 2014 08:10 Go to next message
David Song is currently offline David SongFriend
Messages: 217
Registered: April 2011
Senior Member
Hi all,

1,how to load and apply CSS with custom class( .myClass {...}) to custom widgets ?
2,with browser-based widgets, how to pass json to javascript function? In my code below, I try to execute javascript function with json param, but not work.

StringBuffer script = new StringBuffer();
        script.append( "init(JSON.parse(");
        script.append(json);
        script.append("));" );
        BrowserUtil.evaluate(browser, script.toString(), new BrowserCallback() {
			@Override
			public void evaluationSucceeded(Object result) {
				System.out.println("javascript run succeed!");
			}
			@Override
			public void evaluationFailed(Exception exception) {
				System.out.println("javascript run failed!");
			}
		});


Best Regards
David
Re: two questions about custom widget? [message #1239602 is a reply to message #1237240] Tue, 04 February 2014 15:19 Go to previous message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 396
Registered: July 2009
Senior Member
Hello.

> 1,how to load and apply CSS with custom class( .myClass {...}) to custom
> widgets ?

If you talk about the custom theming support (i.g. RWT.CUSTOM_VARIANT),
we currently do not have public API for that.

If you want to simply include CSS files with your custom widget to load
directly into the browser, you need to register them as a resource (just
like the JS file) and attach them to the documents head at runtime.
There are a number of solutions for that, e.g.:

http://www.codeproject.com/Articles/591062/How-to-add-JavaScript-and-CSS-f

Take care not to add the same CSS file twice. If you are creating a
browser widget based custom widget you can also generate your html at
runtime and add it into the head then.

> 2,with browser-based widgets, how to pass json to javascript function?
> In my code below, I try to execute javascript function with json param,
> but not work.
>
> StringBuffer script = new StringBuffer();
> script.append( "init(JSON.parse(");
> script.append(json);
> script.append("));" );
> BrowserUtil.evaluate(browser, script.toString(), new
> BrowserCallback() {
> @Override
> public void evaluationSucceeded(Object result) {
> System.out.println("javascript run succeed!");
> }
> @Override
> public void evaluationFailed(Exception exception) {
> System.out.println("javascript run failed!");
> }
> });

Your JSON string is likely already parsed by putting it in the
"evaluate" method. Unless you are actually escaped your JSON into a
JavaScript string you can (must) skip the "JSON.parse" call.

Greetings,
Tim
--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:rowTemplate tooltips for image cells
Next Topic:Dialog "Configuration for..."
Goto Forum:
  


Current Time: Thu Apr 25 10:35:36 GMT 2024

Powered by FUDForum. Page generated in 0.03913 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top