Hi François, I like your solution as it seems more flexible. I tried to implement it as follows:
/js/jquery.autocomplete.js: *jQuery.noConfict();* *(function($) {* * $.extend(Tapestry.Initializer, {* * bignibou_autocomplete : function(specs) {* * $("#accountPostcode").autocomplete({* * source : function(request, response) {* * var jqxhr = $.ajax({* * url : specs.link,* * type : "GET",* * data : {* * term : request.term* * },* * dataType : "json"* * }).fail(function() {* * console.log("error:");* * console.log(jqxhr.statusText);* * }).success(function(data) {* * response(data);* * });* * },* * minLength : 2* * });* * }* * });* *})(jQuery);* * * >From my T5 java page: * * *@Import(library = "context:/js/jquery.autocomplete.js")* *...* * @AfterRender public void afterRender() { Link jSonPostcodesWithQueryParamLink = pageRenderLinkSource.createPageRenderLink(JSonPostcodesWithQueryParam.class); String link = jSonPostcodesWithQueryParamLink.toAbsoluteURI(); JSONObject specs = new JSONObject(); specs.put("link", link); javaScriptSupport.addInitializerCall("bignibou_autocomplete", specs); } * I get the following T5 error: Function Tapestry.Initializer.bignibou_autocomplete() does not exist. Any idea what I am getting wrong? Regards, J. 2012/1/30 Julien Martin <bal...@gmail.com> > Thanks Lenny, > Is the dependency to "com.flowlogix.web.services.AssetMinimizer" > necessary? > Is there a "pure-T5" way of retrieving the string from the script? > Here is what I came up with borrowing from your code: > > > *javaScriptSupport.addScript(getString(openStream(jsAutocomplete)), link); > * > > * > * > * > private String getString(InputStream is) throws IOException { > BufferedReader br = new BufferedReader(new InputStreamReader(is)); > StringBuilder sb = new StringBuilder(); > String line = null; > > while ((line = br.readLine()) != null) { > sb.append(line).append("\n"); > } > > return sb.toString(); > } > > private InputStream openStream(Asset asset) throws IOException { > return asset.getResource().openStream(); > } > * > > It is very low-level but does work. > regards, > J. > > 2012/1/30 Lenny Primak <lpri...@hope.nyc.ny.us> > >> Take a look at these: >> >> >> http://code.google.com/p/flowlogix/source/browse/tapestry-services/src/main/java/com/flowlogix/web/mixins/ColorHighlight.java >> >> http://code.google.com/p/flowlogix/source/browse/tapestry-services/src/main/resources/com/flowlogix/web/mixins/ColorHighlight.js >> >> On Jan 30, 2012, at 5:14 AM, Julien Martin wrote: >> >> > Thanks François, >> > I have actually. The issue is how to replace a variable within the js >> file >> > with the appropriate value. This seems easy enough with an inline >> script as >> > above but if the script is located in its own file I don't know how to >> > achieve the desired effect. >> > Regards, >> > Julien. >> > >> > Le 30 janvier 2012 11:04, François Facon <francois.fa...@atos.net> a >> écrit : >> > >> >> Hi Julien, >> >> >> >> did you try the use of @Import to import your js file as explained >> >> http://tapestry.apache.org/javascript.html? >> >> >> >> Regards >> >> François >> >> >> >> 2012/1/30 Julien Martin <bal...@gmail.com>: >> >>> Hi Thiago! >> >>> >> >>> Using your advice, I managed to generate the link easily. I have also >> >> moved >> >>> the script to a separate file as advised. >> >>> >> >>> Now what remains unclear to me is that the *addScript* method takes a >> >>> String and not a url to my javascript file. >> >>> >> >>> So on the one hand I have my link, on the other my javascript file. I >> >>> understand the rationale behind the addScript method: formatting the >> >>> content of the js file with one or several variables passed as the >> second >> >>> argument but what I have is js file not a short script as in the >> >>> documentation: >> >>> >> >>> javaScriptSupport.addScript( >> >>> >> >>> "$('%s').observe('click', hideMe());", >> >>> container.getClientId()); >> >>> >> >>> How do I pass my js file to the addScript method or do I use another >> >> method? >> >>> >> >>> Regards, >> >>> >> >>> Julien. >> >>> >> >>> 2012/1/30 Thiago H. de Paula Figueiredo <thiag...@gmail.com> >> >>> >> >>>> On Sun, 29 Jan 2012 19:22:31 -0200, Julien Martin <bal...@gmail.com> >> >>>> wrote: >> >>>> >> >>>> Thiago, >> >>>>> >> >>>> >> >>>> Hi! >> >>>> >> >>>> >> >>>> Yes it is indeed a Tapestry page. Here is the java code for it (there >> >> is >> >>>>> no template for this page): >> >>>>> >> >>>> >> >>>> So the correct way of generating an URL for a page is to @Inject >> >>>> PageRenderLinkSource and use one of its methods. They return a Link. >> >> Pass >> >>>> the result of the toAbsoluteURI() method to your JavaScript method by >> >>>> @Inject'ing JavaScriptSupport and using its addScript() method. >> >>>> >> >>>> In addition, as you're returning JSON content, instead of return >> >>>> TextStreamResponse, you can return a JSONObject or a JSONArray. >> >>>> >> >>>> >> >>>> -- >> >>>> Thiago H. de Paula Figueiredo >> >>>> Independent Java, Apache Tapestry 5 and Hibernate consultant, >> developer, >> >>>> and instructor >> >>>> Owner, Ars Machina Tecnologia da Informação Ltda. >> >>>> http://www.arsmachina.com.br >> >>>> >> >> >> >> --------------------------------------------------------------------- >> >> 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 >> >> >