Inject scripts in a widget


I’m trying to create a widget, which is a wrapper for a jQuery based image gallery library. I got it work if css and javascript are injected in the widgetset descriptor. Then I call JSNI for gallery bootstrap and everything is all right.

Now I want to let the user choose the gallery configuration, which means change a javascript file and two css files. I’ve got the css be included in the DOM as link elements. css files are referenced as resources, theme resources. When the configuration changes, href attribute is changed. The problem is with the css script. All the scripts cannot be included simultaneously, so I have to dynamically change the script for the selected gallery configuration.

I’ve added a script element in the DOM of the component. When configuration changes, the src attribute is changed to reference the new file, also a theme resource. With Firebug I can see the attribute changes, but the browser does not load it’s content. In fact a javascript exception is thrown, probably because the script is not loaded. Besides, I musn’t call the gallery bootstrap until that script is loaded.

I’ve though to add those scripts as strings instead of a resource and replace the text of the script element with the new one. I don’t know if that is an elegant solution and if it would work. The scripts are about 100KB in size.

I’ve also thought to create one component for each gallery model, but it does I don’t like it too much either.

Any ideas?


I am trying to do same thing( jQuery based image gallery library) with Vaadin 7 and please show how you have achieved this…

Caused by: java.lang.UnsatisfiedLinkError: com.example.vaadinsample.client.ui.MyComponentWidget.sayHello(Ljava/lang/String;)V
	at com.example.vaadinsample.client.ui.MyComponentWidget.sayHello(Native Method)
	at com.example.vaadinsample.client.ui.MyComponentWidget$1.buttonClick(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.vaadin.event.ListenerMethod.receiveEvent(
	... 81 more

my compilations is success, and I don’t know what I am doing wrong. I have used Vaadin plugin to compile widgets



 Detecting available criteria ...
Jun 06, 2012 10:47:46 PM com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer findAcceptCriteria
INFO: Searching for accept criteria..
Jun 06, 2012 10:47:48 PM com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer findAcceptCriteria
INFO: Search took 1361ms
               creating mapping for com.vaadin.event.dd.acceptcriteria.And
               creating mapping for com.vaadin.ui.AbstractSelect.TargetItemIs
               creating mapping for com.vaadin.ui.AbstractSelect.AcceptItem
               creating mapping for com.vaadin.event.dd.acceptcriteria.ServerSideCriterion
               creating mapping for com.vaadin.event.dd.acceptcriteria.SourceIsTarget
               creating mapping for com.vaadin.event.dd.acceptcriteria.Not
               creating mapping for com.vaadin.ui.Table.TableDropCriterion
               creating mapping for com.vaadin.event.dd.acceptcriteria.Or
               creating mapping for com.vaadin.event.dd.acceptcriteria.SourceIs
               creating mapping for com.vaadin.event.dd.acceptcriteria.TargetDetailIs
               creating mapping for com.vaadin.event.dd.acceptcriteria.AcceptAll
               creating mapping for com.vaadin.ui.Tree.TargetInSubtree
               creating mapping for com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor
               creating mapping for com.vaadin.ui.Tree.TreeDropCriterion
               Done. (1seconds)
   Compiling 6 permutations
      Compiling permutation 1...
      Process output
            Compiling permutation 0...
      Compiling permutation 2...
            Compiling permutation 3...
      Compiling permutation 4...
            Compiling permutation 5...
   Compile of permutations succeeded
   Linking into src/main/webapp/VAADIN/widgetsets
      Link succeeded
   Compilation succeeded -- 256.128s

Please avoid multiple posting - for the question about the exception, see
this thread