Option #2 looks promising. I will try it! Thanks.
On Aug 18, 2011, at 4:22 PM, Robert Zeigler <robert.zeig...@roxanemy.com> wrote: > If GWT is generating the scripts directory, why doesn't it know the > directory? Or are you telling it the directory to use? > > In any event, I can think of a couple of possibilities. Basically, the > problem is that you don't know the value of the directory until render time, > but Tapestry puts all libraries to be imported into the document head, and > all code to be executed (such as a variable declaration) occurs after page > load (which is after loading the gwtSupport.js script). > > Option #1 (gross, btw, but it would get the job done): > * Remove the @Import > * @Inject JavaScriptSupport jsSupport; > * In one of the render phase methods, generate the required value and write > it to a file (eg: in the context). > * jsSupport.includeJavaScriptLibrary("your generated file"); > * jsSupport.includeJavaScriptLibrary("context:js/gwtSupport.js"); > > Option #2 (not as gross; still smells, but should work): > * Leave the import in place > * After render: > void afterRender(MarkupWriter writer) { > //find the gwt script: > Element gwtScript; > for(Node n : writer.getDocument().find("html/head").getChildren()) { > if (!(n instanceof Element)) continue; > Element el = (Element) n; > if ("script".equals(el.getName()) && el.getAttribute("src") != > null && el.getAttribute("src").contains("gwtSupport.js")) { > gwtScript = el; > break; > } > } > if (gwtScript == null) > throw new RuntimeException("Couldn't find gwtSupport script!"); > > Element myScript = > getDocument().find("html/head").element("script","type","text/javascript"); > myScript.text("var myvar=" + myGeneratedValue); > myScript.moveBefore(gwtScript); > } > > In option 2, you're leveraging the fact that Tapestry renders a DOM tree on > the server to find the gwtScript element in the document head and insert your > custom script (with variable declaration) before it. > > Neither option is very pretty, but both should work. > > > Robert > > On Aug 18, 2011, at 8/183:37 PM , Lenny Primak wrote: > >> Its a path to the GWT-generated scripts directory. Basically, there can be >> many GWT modules, but supporting scripts are the same, >> even though they are duplicated in different paths, so any path will do, but >> there has to be one, just dynamically generated from >> any of the available components. >> >> Thanks for your help! >> >> On Aug 18, 2011, at 3:34 PM, Robert Zeigler wrote: >> >>> Hm. Can you speak more to what the generated value is supposed to be/do? >>> It appears that it doesn't matter /too/ much what it is since it doesn't >>> matter if multiple component instances overwrite the value? >>> >>> Robert >>> >>> On Aug 18, 2011, at 8/183:24 PM , Lenny Primak wrote: >>> >>>> The variable's value is dynamically generated by the component that is >>>> importing the library. >>>> If there are multiple component, any component instance should win, and >>>> that's ok. >>>> >>>> >>>> On Aug 18, 2011, at 3:22 PM, Robert Zeigler wrote: >>>> >>>>> What if you include a bit of custom js in a separate file that defines >>>>> the variable? >>>>> >>>>> component.js: >>>>> var somevar="someval"; >>>>> >>>>> Then: >>>>> >>>>> @Import(library={"component.js","context:js/gwtSupport.js"}) >>>>> public class GwtSupport{...} >>>>> >>>>> Pretty sure that the order of the libraries in your @Import will be >>>>> honored in the import declarations on the page (but I don't remember >>>>> offhand). >>>>> >>>>> Robert >>>>> >>>>> On Aug 18, 2011, at 8/183:14 PM , Lenny Primak wrote: >>>>> >>>>>> I have a component like this: >>>>>> >>>>>> @Import(library="context:js/gwtSupport.js") >>>>>> public class GwtSupport >>>>>> { >>>>>> // intentionally left blank >>>>>> } >>>>>> >>>>>> >>>>>> gwtSupport.js (actually the GWT component itself which I have no control >>>>>> over) >>>>>> is trying to read a variable. >>>>>> >>>>>> I wasn't able to figure out a way to set it before gwtSupport.js gets >>>>>> included. >>>>>> >>>>>> I tried addInitializerCall, addScript, etc. but they all come after >>>>>> gwtSupport.js is included. >>>>>> >>>>>> What am I missing? >>>>>> >>>>>> >>>>>> >>>>>> --------------------------------------------------------------------- >>>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>>>>> For additional commands, e-mail: users-h...@tapestry.apache.org >>>>>> >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>>>> For additional commands, e-mail: users-h...@tapestry.apache.org >>>>> >>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>>> For additional commands, e-mail: users-h...@tapestry.apache.org >>>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>> For additional commands, e-mail: users-h...@tapestry.apache.org >>> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org