Johannes,

What I have done is to put all of the meat of the javascript code into a
single file which is included in the sj:head and then just have a small
binding snippet code rendered with each tag which calls a binding function
in the main .js file.

The binding snippet is identical for all tags so (using Freemarker), I
simply have a jquery-bind.ftl template and call <#include
"/${parameters.templateDir}/jquery/jquery-bind.ftl" /> at the end of each
one of my tag templates.

I have found that consolidating all the js makes the framework much more
maintainable and extensible (you don't have to re-write the js for use with
different template engines). Doing it this way has also provided a simple
way to allow plugging-in user developed custom widget (basically I provide a
hook that just calls the same bind function and adds any custom .js code for
their widget).

You can find the source code (and incomplete documentation) for this at:
http://code.google.com/p/struts2-jquery-plugin/

This way, the addition to the freemarker templates is almost thoughtless and
the you don't place the (IMO) overburdening requirement to add yet another
<footer/> tag for the developer.

- Eric


On Wed, Aug 12, 2009 at 3:46 PM, Johannes Geppert <jo...@web.de> wrote:

>
> Hello,
>
> maybe anybody can give my some input for an idea I have today.
> I work on the current struts2-jquery-plugin.
> http://code.google.com/p/struts2-jquery/
>
> At the moment the tags create after each generated html tag
> an separate <script> tag like this:
>
> <div id="mydiv1"></div>
> <script type="text/javascript">
> $(document).ready(function () { do something with mydiv1; });
> </script>
> <div id="mydiv2"></div>
> <script type="text/javascript">
> $(document).ready(function () { do something with mydiv2; });
> </script>
>
> This looks a little bit dirty, so I look for a way to collect all the
> generate javascript stuff
> to one big javascript
>
> <div id="mydiv1"></div>
> <div id="mydiv2"></div>
> <script type="text/javascript">
> $(document).ready(function () { do something with mydiv1;  do something
> with
> mydiv2; });
> </script>
>
> Maybe all the generated javascript can be put on an Stack
> and can be rendered with an separate sj:footer tag.
>
> The JSP can look like this:
> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
> <html>
>  <head>
>    <sj:head/>
>  </head>
>  <body>
>    <sj:div id="div1"></sj:div>
>    <sj:div id="div2"></sj:div>
>    <sj:a id="link1" href="%{ajaxurl}" target="result">Link</sj:a>
>    <sj:datepicker />
>    <sj:footer/>
>  </body>
> </html>
>
> Is there a way or should I put this idea out of my mind?
>
> Best Regards
> Johannes Geppert
>
> -----
> ---
> web: http://www.jgeppert.com
> twitter: http://twitter.com/jogep
>
> --
> View this message in context:
> http://www.nabble.com/Create-a-single-javascript-tp24935752p24935752.html
> Sent from the Struts - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
> For additional commands, e-mail: dev-h...@struts.apache.org
>
>

Reply via email to