Hello,

I am using Tapestry 5.4 beta 6. 
I am trying to add a script block at the very end of the page body, after 
tapestry has written all its javascript.
I know there are 2 ways: using javascriptSupport.addScript or 
javascriptSupport.require or creating one js file par page and load it via AMD.
But i want it to output a simple raw javascript block at the very end of the 
page. 
I tried to create a component “Javascript” to do just that, but I can’t figure 
how to render at the very end of the page after all other javascript. 
The reason is that sometimes outputting a block in the main page is simpler 
than to create one js file per page and then to require it.
Also it’s quit complicated to always have to modify Java files to add a bit of 
javascript.

Here is my component:

public class Javascript {

   @Environmental
   private JavaScriptSupport javaScriptSupport;

   @Inject
   private ComponentResources componentResources;

   void setupRender(MarkupWriter writer) {
       writer.element("script").attribute("type", "text/javascript");
   }

   public void afterRender(final MarkupWriter writer) {
       Element wrapper = writer.getElement();
       writer.end();
       final String bodyMarkup = wrapper.getChildMarkup();
       wrapper.remove();
       javaScriptSupport.addScript(bodyMarkup);

   }
}

This component does work, but I don’t like the fact that Tapestry is evaluating 
my js. 
I want a rather simple output just before the “html” close tag:

<script type=“text/javascript">
        var myscript = “goes here”;
</script>

If I add multiple time this component, I want it to stack all the inline 
javascript together in the order they appeared in the page. 
I use AMD a lot but forcing AMD is not a good solution. I think that was the 
way it worked with Tapestry 5.3.

Also the  javaScriptSupport.addScript method is deprecated, the  
javaScriptSupport.require should be used, but it does not the same. 
What is the equivalent of addScript in Tapestry5.4

Is there a way to bypass pageinit to initialize or add scripts and have them at 
the end of the page ?

Thanks for your help.

Numa
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to