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
Song David is currently offline Song David
Messages: 190
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 Buschtoens
Messages: 386
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:RAP MarkUp containing & character
Next Topic:[POLL] BDD with RAP
Goto Forum:
  


Current Time: Sun Oct 26 03:07:24 GMT 2014

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

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