Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for 
change notification.

The following page has been changed by DanielJue:
http://wiki.apache.org/tapestry/Tapestry5AndJavaScriptExplained

The comment on the change is:
Described when to put renderSupport.addScript in @CleanupRender. (5.0.13 compat)

------------------------------------------------------------------------------
  package net.godcode.jsclarity.mixins;
  
  import org.apache.tapestry.ClientElement;
- import org.apache.tapestry.PageRenderSupport;
+ import org.apache.tapestry.RenderSupport;
  import org.apache.tapestry.TapestryConstants;
  import org.apache.tapestry.annotations.AfterRender;
  import org.apache.tapestry.annotations.IncludeJavaScriptLibrary;
@@ -60, +60 @@

        private String message;
        
        @Inject
-       private PageRenderSupport renderSupport;
+       private RenderSupport renderSupport;
        
        @InjectContainer
        private ClientElement element;
@@ -223, +223 @@

  You can apply this annotation to page, component, or mixin classes. You must 
provide it with either the name of a javascript file as a string, or an array 
of files. These strings represent locations in the classpath, which will be 
searched in a relative manner. Whenever you use this annotation, Tapestry also 
adds the prototype and scriptaculous libraries before the files specified in 
the annotation automatically. It's also smart enough not to add the same file 
twice. To top it off, if your files cannot be found Tapestry will fail fast by 
throwing an exception. To me, this is just great. I don't want my application 
to just suck it up and keep going. The assumption made by Tapestry here is the 
same for any injected asset files: that they are an integral part of the 
application's front end and so the breaking of the application is a logical 
consequence when they are missing.
  
  
- == PageRenderSupport ==
+ == RenderSupport ==
  
- The last missing piece is the 
[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/PageRenderSupport.html
 PageRenderSupport] service. Look again at the `afterRender` method of the 
mixin class:
+ The last missing piece is the 
[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/RenderSupport.html
 RenderSupport] service. Look again at the `afterRender` method of the mixin 
class:
  
  {{{
        @AfterRender
@@ -247, +247 @@

  </script>
  }}}
  
- That basically says it all. Calls to `PageRenderSupport#addScript` result in 
a `<script>` block being generated at the foot of your page. If you want to see 
exactly what happens in the javascript then you'll want to look at the 
`tapestry.js` file, where you can find the source of `Tapestry.onDOMLoaded`. 
You could just take my word and know that the function argument it receives is 
called after the document has loaded, effectively associating the contained 
code with the `onload` event of the document. In our case we can know that the 
element to which we are attaching our javascript object will have loaded. If 
multiple calls are made to `PageRenderSupport#addScript`, then the scripts will 
be accumulated and output in a single call to `Tapestry.onDOMLoaded`.
+ That basically says it all. Calls to `RenderSupport#addScript` result in a 
`<script>` block being generated at the foot of your page. If you want to see 
exactly what happens in the javascript then you'll want to look at the 
`tapestry.js` file, where you can find the source of `Tapestry.onDOMLoaded`. 
You could just take my word and know that the function argument it receives is 
called after the document has loaded, effectively associating the contained 
code with the `onload` event of the document. In our case we can know that the 
element to which we are attaching our javascript object will have loaded. 
  
+ If multiple calls are made to `RenderSupport#addScript`, then the scripts 
will be accumulated and output in a single call to `Tapestry.onDOMLoaded`.  
Take note if you are calling `RenderSupport#addScript` from a method used to 
restart the render cycle.  For instance, you could have a tree menu component 
that uses an @AfterRender method to iterate over the list of tree nodes, while 
the `RenderSupport#addScript` is used to initialize the tree.  Since you only 
want to initialize the tree once, you may want to do something like this:
+ 
+ {{{
+ 
+       @AfterRender
+       private boolean phase7() {
+               heartbeat.end();
+                 //if there is another element in the tree, 
+                 //go to the @BeginRender method again.
+               return (!iterator.hasNext());
+       }
+ 
+       @CleanupRender
+       void phase8(MarkupWriter writer) {
+               writer.end();
+               String jsString = "";
+               jsString += "Event.observe( window, 'load', function() {";
+               jsString += " %s = new JSDragDropTree(); ";
+               jsString += " %s.setTreeId('reporttree'); ";
+               jsString += " %s.setImageFolder('../images/tree/'); ";
+               jsString += " %s.setRenameAllowed(false); ";
+               jsString += " %s.setDeleteAllowed(false); ";
+               jsString += " %s.initTree(); ";
+               jsString += " %s.expandAll(); ";
+               jsString += " } );";
+               renderSupport.addScript(String.format(jsString, treeObjectName,
+                               treeObjectName, treeObjectName, treeObjectName, 
treeObjectName,
+                               treeObjectName, treeObjectName));
+       }
+ 
+ }}}
+ 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to